Question : Due to growth within the area code, the telephone exchange is being reassigned to the area code. The data set Clients.Piedmont includes the variable Phone, which contains telephone numbers in the form 919-555-1234. Which of the following programs will correctly change the values of Phone? 1. data work.piedmont(drop=areacode exchange); set clients.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 clients.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 clients.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then substr(phone,5,3)='920'; run; 4. data work.piedmont(drop=areacode exchange); set clients.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then phone=substr('920',1,3); run;
Correct Answer : 3
The SUBSTR function replaces variable values if it is placed on the left side of an assignment statement. When placed on the right side (Read explanation from Question ), the function extracts a substring
Question : Suppose you need to create the variable FullName by concatenating the values of FirstName, which contains first names, and LastName, which contains last names. What's the best way to remove extra blanks between first names and last names?
1. data work.maillist; set retail.maillist; length FullName $ 40; fullname=trim firstname||' '||lastname; run; 2. data work.maillist; set retail.maillist; length FullName $ 40; fullname=trim(firstname)||' '||lastname; run; 3. data work.maillist; set retail.maillist; length FullName $ 40; fullname=trim(firstname)||' '||trim(lastname); run; 4. data work.maillist; set retail.maillist; length FullName $ 40; fullname=trim(firstname||' '||lastname); run;
Correct Answer : 2
Explanation: The TRIM function removes trailing blanks from character values. In this case, extra blanks must be removed from the values of FirstName. Although answer c also works, the extra TRIM function for the variable LastName is unnecessary. Because of the LENGTH statement, all values of FullName are padded to 40 characters.
Question : The SAS data set SASUSER.HOUSES contains a variable PRICE which has been assigned a permanent label of "Asking Price". Which SAS program temporarily replaces the label "Asking Price" with the label "Sale Price" in the output? 1. proc print data = sasuser.houses; label price = "Sale Price"; run; 2. proc print data = sasuser.houses label; label price "Sale Price"; run; 3. proc print data = sasuser.houses label; label price = "Sale Price"; run; 4. proc print data = sasuser.houses; price = "Sale Price"; run;
Correct Answer : 3 SAS variables can have these attributes: name type length informat format label position in observation index type Two variable attributes, format and label, affect how variable values and names are represented when they are printed or displayed. These attributes are assigned with different statements
In procedure output, SAS automatically writes the variables with the names that you specify. However, you can designate a label for some or all of your variables by specifying a LABEL statement either in the DATA step or, with some procedures, in the PROC step of your program. Your label can be up to 256 characters long, including blanks.
In procedure output, SAS automatically writes the variables with the names that you specify. However, you can designate a label for some or all of your variables by specifying a LABEL statement either in the DATA step or, with some procedures, in the PROC step of your program. Your label can be up to 256 characters long, including blanks. If you specify the LABEL statement in the DATA step, the label is permanently stored in the data set. If you specify the LABEL statement in the PROC step, the label is associated with the variable only for the duration of the PROC step. In either case, when a label is assigned, it is written with almost all SAS procedures. The exception is the PRINT procedure. Whether you put the LABEL statement in the DATA step or in the PROC step, with the PRINT procedure you must specify the LABEL option as follows: proc print data=report label; run;