The following SAS program is submitted: data work.company; set work.dept1(keep = jobcode) work.dept2(rename = (jcode = jobcode)); run; Which one of the following is the result?
Explanation: The variable jcode in the second dataset is renamed as JOBCODE and since there is no BY variable specified, the datasets are simply appended one on top without any overwriting.
The code above can be rewritten in a way that set and the two datasets are in the same line. So the set statement continues till the end of work.dept2(rename = (jcode = jobcode));
Since there is a semicolon that the end of the set statement, that is not an issue.
Renaming the dataset takes place during the set statement, therefore the name is current. So both datasets have jobcode variable.
"The RENAME= data set option in the SET statement renames variables in the input data set. You can use the new names in programming statements for the current DATA step. " - SAS H And D
Question :
The following SAS program is submitted: data work.passengers; if OrigPassengers = . then OrigPassengers = 100; TransPassengers = 100; OrigPassengers = .; NonPaying = 10; TotalPassengers = sum (OrigPassengers, TransPassengers); run; Which one of the following is the value of the TOTALPASSENGERS variable in the output data set?
Explanation: PDV initializes all variables in data step to missing first. So if statement yields true, so value of origpassenger becomes 100. Then transpassenger is assigned value of 100. Next step value of origpassenger is overwritten with missing value. So when you add using sum function which ignores missing value, values of orignpassenger and transpassenger ie sum(.,100) gives you 100. Thus answer is 1.
Question :
The following SAS program is submitted: data work.staff; JobCategory = 'FA'; JobLevel = '1'; JobCategory = JobCategory || JobLevel; run; Which one of the following is the value of the variable JOBCATEGORY in the output data set?
Explanation: length of JobCategory already set to 2 by the first assignment statement
jobcategory='FA';
after this jobcategory variable's length is two bytes,it can hold only two bytes.
Eventhough there is no mistake in the step
jobcategory=jobcategory || joblevel;
jobcategory carries the value FA.
behind the scenes: 1. the PDV writes the variables jobcategory (length 2) joblevel (length 1)with missing values 2. at the execution jobcategory gets FA and joblevel gets 1 3. Access Mostly Uused Products by 50000+ Subscribers
Actual value of the variable jobcatogery is FA1 How ever since sas first finds the value of Job category as FA it sets the length to 2 hence 1 is finally discarded from FA1 to make up to a length of 2.