BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jc3992
Pyrite | Level 9

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

7 REPLIES 7
Reeza
Super User

@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? 

jc3992
Pyrite | Level 9
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        
Reeza
Super User

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        

 

Astounding
PROC Star

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.

jc3992
Pyrite | Level 9

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!

ballardw
Super User

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
Pyrite | Level 9
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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 888 views
  • 2 likes
  • 4 in conversation