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 with our comprehensive quiz. Study with multiple-choice questions, detailed explanations, and helpful hints to boost your confidence. Ace your certification test!

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.


How can you extract the sex identifier from the variable IDCode, where the fourth character indicates sex?

  1. Sex=scan(idcode,4);

  2. Sex=scan(idcode,4,1);

  3. Sex=substr(idcode,4);

  4. Sex=substr(idcode,4,1);

The correct answer is: Sex=substr(idcode,4,1);

The correct choice effectively extracts only the specific character that indicates sex from the IDCode variable, which is positioned at the fourth character. The function used is `substr`, which is designed to return a substring from a given string. In this instance, the `substr(idcode, 4, 1)` function call specifies two important parameters: the starting position of the substring (which is 4, referring to the fourth character in the string) and the length of the substring (which is 1, meaning only one character is being extracted). This ensures that only the sex identifier, located at the fourth position in the IDCode, is returned and stored in the variable named Sex. The other choices do not correctly achieve the goal of isolating the sex identifier for several reasons. For instance, using `scan` may not appropriately extract individual characters based on their position within a string in this context, while `substr(idcode,4)` lacks the length specification required to limit the output to a single character. Thus, choice D is the most precise and appropriate method for retrieving the desired information from the IDCode variable.