Subject Name: Data Management for Analytics
Software used: SAS
Choose the best single option.
Q10. Consider a categorical variable LOCATION with 10 levels: “location1”- “location10”. In order to create a new numeric variable which has only the numeric value extracted from each level name, which of the following SAS code will work?
a. location_num = input(substr(location,2,2),2.);
b. location_num = substr(location,2,2);
c. location_num = substr(location,9,2);
d. location_num = input(substr(location,9,1),1.);
e. location_num = input(substr(location,9,2),2.);
The correct option is,
e. location_num = input(substr(location,9,2),2.);
Explanation :
in a above mentioned code SUBSTR function will first cut the string from 9th position to 10th position because
syntax of substr is
substr(string,starting position,number of positions to keep)
so now we got the number from each string but we have to convert it to numeric
so we use input function which has syntax
input(variable name, informat)
which converts it to numeric, so it becomes a numeric variable.
Get Answers For Free
Most questions answered within 1 hours.