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?
A. The variable JCODE is written to the output data set.
B. The variable JOBCODE is written to the output data set.
C. Neither variable JCODE nor JOBCODE is written to the output data set.
D. The program fails to execute due to errors.
Click Comment link to get answer
The answer must be B. 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..!!!
ReplyDeleteAnswer is B
ReplyDeleteanswer is D . no semi-colon after set stmt.
ReplyDeleteThere isn't supposed to be a semicolon there. This is a concatenation-style merge operation.
Deletegreat catch on the semi-colon missing in the SET statement (D).
ReplyDeleteif semi-colon given in 2nd line then it is error option (D). Answer is (B) as set function is for 2 nd and 3 rd line and renamed properly.
Deleteset statement extends upto it finds a semicolon. So D is NOT the answer. B is the answer.
ReplyDeleteYaah..Ans is B.
ReplyDeleteIf there is semicolon after set statement then the answer would be D.
there IS a semicolon after the set stmt. in this case the set statement is taking 2 lines. answer is B.
ReplyDeleteAnswer is B.
ReplyDeleteThe 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
thanks
DeleteThis comment has been removed by the author.
DeleteYour detailed comments in response to most of the questions have been helpful. Thanks!
Deletethere shud be a BY variable after a set statement ..right?
ReplyDeleteBy var after set stmt is not required as it can be either concatentaion or interleaving . Here is is concatentaion so no by var is required. ans is B
DeleteAns is B
ReplyDeleteB
ReplyDeleteB
ReplyDeleteThe variable jcode in the second dataset is renamed as JOBCODE
B
ReplyDeleteIt is amazing that you have finally reached this point. i think that you had to overcome many obstacles that require the good physical availability.
ReplyDelete