Statistical Analysis System (SAS) Programming Certification Practice Exam

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the SAS Programming Certification Exam. Study with multiple choice questions and detailed explanations. Enhance your exam readiness!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


If Address2 contains "Piscataway, NJ", how do you assign the state abbreviation to a new variable State?

  1. State=scan(address2,2);

  2. State=scan(address2,13,2);

  3. State=substr(address2,2);

  4. State=substr(address2,13,2);

The correct answer is: State=scan(address2,2);

The choice to assign the state abbreviation to a new variable State using the function scan is appropriate because this function is designed to parse strings by separating them according to specified delimiters. In the example given, "Piscataway, NJ", scan will split the string wherever it encounters a space or a comma. When using the scan function with the second argument set to 2, it retrieves the second word from the string after the split. In this case, the second word is "NJ", which is the state abbreviation you wish to extract. This approach effectively targets the state abbreviation without needing to know exactly where it begins or the precise characters that surround it, making it a reliable method for string manipulation in this context. The other options employ either the wrong syntax for the scan function or use the substr function, which extracts a substring based on character positions, potentially leading to incorrect or unexpected results since it does not account for the variable lengths of different state names or positions in the string.