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.


Which program correctly changes the values of the Phone variable from the 919 area code to the 920 area code?

  1. data work.piedmont(drop=areacode exchange); set cert.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then scan(phone,1,3)='920'; run;

  2. data work.piedmont(drop=areacode exchange); set cert.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then phone=scan('920',1,3); run;

  3. data work.piedmont(drop=areacode exchange); set cert.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then substr(phone,1,3)='920'; run;

  4. data work.piedmont(drop=areacode exchange); set cert.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then phone='920'||substr(phone,4); run;

The correct answer is: data work.piedmont(drop=areacode exchange); set cert.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then substr(phone,1,3)='920'; run;

The correct answer effectively uses the `substr` function to change the area code of the Phone variable directly by modifying the substring that represents the area code. When the condition for the area code ('919') and exchange code ('555') is met, the command `substr(phone, 1, 3) = '920';` changes the first three characters of the Phone variable to '920', effectively altering the area code as intended. This approach directly manipulates the specified part of the string within the Phone variable, ensuring that the change is applied to the existing value rather than creating a new one. It’s a valid technique in SAS when you want to modify a part of a character variable without fully reconstructing the variable or needing to concatenate strings. While other options may have appeared plausible, they either do not directly modify the appropriate portion of the Phone variable or may be attempting to assign new values in a way that does not achieve the intended change cleanly. This specificity and directness in modifying substrings makes this solution the most appropriate one for changing the phone area code from 919 to 920.