Hello everyone,
I am doing some SAS certificate questions, and I have run the code below,
and got the different answer as it provided with on the Internet.
The code is as follows:
DATA work.first; Input common $ X; cards; A 10 A 13 A 14 B 9 ; run; DATA work.second; input common $ Y; cards; A 1 A 3 B 4 B 2 ; run; data work.combine; SET work.first; set work.second; run;
The question is: what data values are stored in data set work.combine?
The answer is :
common X Y
A 10 1
A 13 3
B 14 4
B 9 2
But my result when I tested it in SAS is:
common X
A 10
A 13
A 14
B 9
Would anyone tell me which is the correct?
Thank you very much!!
This code duplicates your stated output:
DATA work.first; Input common $ X; cards; A 10 A 13 A 14 B 9 ; run; DATA work.second; input common $ x; cards; A 1 A 3 B 4 B 2 ; run; data work.combine; SET work.second; set work.first; run;
Note that the work.second has the same variable name X instead of Y and the order of the two set statements is different.
@jc3992 wrote:
Hello everyone,
I am doing some SAS certificate questions, and I have run the code below,
and got the different answer as it provided with on the Internet.
The code is as follows:
DATA work.first; Input common $ X; cards; A 10 A 13 A 14 B 9 ; run; DATA work.second; input common $ Y; cards; A 1 A 3 B 4 B 2 ; run; data work.combine; SET work.first; set work.second; run;The question is: what data values are stored in data set work.combine?
The answer is :
common X Y
A 10 1
A 13 3
B 14 4
B 9 2
But my result when I tested it in SAS is:
common X
A 10
A 13
A 14
B 9
Would anyone tell me which is the correct?
Thank you very much!!
Post your log. I ran the exact code and get a different output. I suspect you've named them both X instead of X and Y?
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 DATA work.first; 74 Input common $ X; 75 cards; NOTE: The data set WORK.FIRST has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 80 ; 81 run; 82 83 DATA work.second; 84 input common $ Y; 85 cards; NOTE: The data set WORK.SECOND has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 90 ; 91 run; 92 93 data work.combine; 94 SET work.first; 95 set work.second; 96 run; NOTE: There were 4 observations read from the data set WORK.FIRST. NOTE: There were 4 observations read from the data set WORK.SECOND. NOTE: The data set WORK.COMBINE has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 97 98 99 100 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 113
The log says 4 obs and 3 variables which doesn't match what you posted, since it had only one variable.
I still think the answer from my initial post is what happened.
@jc3992 wrote:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 DATA work.first; 74 Input common $ X; 75 cards; NOTE: The data set WORK.FIRST has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 80 ; 81 run; 82 83 DATA work.second; 84 input common $ Y; 85 cards; NOTE: The data set WORK.SECOND has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 90 ; 91 run; 92 93 data work.combine; 94 SET work.first; 95 set work.second; 96 run; NOTE: There were 4 observations read from the data set WORK.FIRST. NOTE: There were 4 observations read from the data set WORK.SECOND. NOTE: The data set WORK.COMBINE has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 97 98 99 100 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 113
The answer is correct. Somehow, the program you tested is different than the one in the practice exam.
Incidentally, is this a SAS provided practice exam? It would be highly unusual for SAS to add a RUN statement after a CARDS statement.
The data sets were from my own creation.
SAS did not give me the code to produce the data sets.
Thank you very much for your help!
This code duplicates your stated output:
DATA work.first; Input common $ X; cards; A 10 A 13 A 14 B 9 ; run; DATA work.second; input common $ x; cards; A 1 A 3 B 4 B 2 ; run; data work.combine; SET work.second; set work.first; run;
Note that the work.second has the same variable name X instead of Y and the order of the two set statements is different.
DATA work.first; Input common $ X; cards; A 10 A 13 A 14 B 9 ; run; DATA work.second; input common $ Y; cards; A 1 A 3 B 4 B 2 ; run; data work.combine; SET work.first; set work.second; run;
This was what I used to run the command earlier. Sorry after adding "Proc Print data=work.combine;"
I found it was because of the screen blocking the other half of the output.
Thank you very much!!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.