BookmarkSubscribeRSS Feed
San_0611
Calcite | Level 5

Data  One:

 

Name          IDnum  

Amy             125

Lily               652

John            452

Mark           123

 

Data Two:

 

Name          IDnum  

Amy             125

Lily               652

Amanda       452

Mark           123

 

data  work.new;

  set  One  Two;

run;

 

 

How  many  variables  are  there in  output data  set?

 

Options are  like 3,4  Or  program  fails 

 

 

Thanks  in advance  for  help. 

16 REPLIES 16
kiranv_
Rhodochrosite | Level 12

another great option and this option helps us in learning. that is d) run the code with data you shown 

San_0611
Calcite | Level 5
How to create Date sets One and Two which are given above in SAS
University edition?

SuryaKiran
Meteorite | Level 14

SET statement here will append both the datasets if they have same datatypes. If both has same datatypes then output will have (4+4) records.
Since you don't have that option I assume that datatypes doesn't match and hence you will get an error.

 

/* This will have warning because the lengths for IDnum are different */
data one;
infile datalines dlm=',' dsd missover;
input Name:$8. IDnum:$20.;
datalines; 
Amy,125
Lily,652
John,452
Mark,123
;
data two;
infile datalines dlm=',' dsd missover;
input Name:$8. IDnum $50.;
datalines; 
Amy,125
Lily,652
Amanda,452
Mark,123
;
data want;
set one two;
run;
/* This will throw an error because IDnum is defined as character in one dataset and numeric in another */
data one;
infile datalines dlm=',' dsd missover;
input Name:$8. IDnum;
datalines; 
Amy,125
Lily,652
John,452
Mark,123
;
data two;
infile datalines dlm=',' dsd missover;
input Name:$8. IDnum $50.;
datalines; 
Amy,125
Lily,652
Amanda,452
Mark,123
;
data want;
set one two;
run;
Thanks,
Suryakiran
San_0611
Calcite | Level 5

My question is  How  many  variables are  there  in  output  data  set  ,  not  the  number  of  records or  observations.

 

Thanks,

Sanika

Kurt_Bremser
Super User

With two identically named variables in both input datasets, the answer is either "2" or "will fail". The second happens if identically named variables have different types. Different lengths can cause WARNINGs.

San_0611
Calcite | Level 5

How  to create the  data sets  One  and Two  in SAS  university  edition to run  the  above  code ?

I am  Base  SAS  learner 

 

 

Also  if  there are  two variables  in  each  data  set which  are  same  , then  how  the  output  data set  new will have  4  variables ?

 

 

Please explain  in  brief.

 

Thanks,

Sanika

ballardw
Super User

@San_0611 wrote:

How  to create the  data sets  One  and Two  in SAS  university  edition to run  the  above  code ?

I am  Base  SAS  learner 

 

 

Also  if  there are  two variables  in  each  data  set which  are  same  , then  how  the  output  data set  new will have  4  variables ?

 

 

Please explain  in  brief.

 

Thanks,

Sanika


If you did not make any spelling errors in your original post I would ask 1) where you got the options 3, 4 or fail and 2) why wasn't 2 an option.

 

Are you claiming above that the "answer" is supposed to be 4? Then you have not provided sufficient information OR the source of your answer is incorrect.

San_0611
Calcite | Level 5
This question is from my Base SAS certification exam, and my thinking about
the answer of the problem is also "2". ,but this option is not provided in
the question and I am really sure about it. That is why I answered it as
"program fails"
But I don't know whether it is correct or wrong answer .
There is the fourth option but I don't remember it exactly ,but I am sure
that was not "2".

So just want to confirm what is the correct answer .


Thanks.

Kurt_Bremser
Super User

How are the datasets presented for this question? Are they provided electronically as SAS datasets, or as data step code with datalines? Just showing a visual example (like in your first post) is not sufficient at all, because that tells us nothing about variable attributes, which are crucial for the answer.

If all information you got is what you presented in your initial post, then the question is made up very badly, and you should report that.

San_0611
Calcite | Level 5
The question was shown as I said in first post just the two tables are
given for data set One and data set Two, there is no any dataline code or
nothing said about the type or length of variables,
As I remember the only difference in those two data sets is in the
observation number 3 in Variable name.

Thanks

Kurt_Bremser
Super User

Then present the answer 2 with this code as proof:

data one;
input Name $ IDnum;
datalines;
Amy 125
Lily 652
John 452
Mark 123
;
run;

data two;
input Name $ IDnum;
datalines;
Amy 125
Lily 652
Amanda 452
Mark 123
;
run;

data want;
set one two;
run;

proc print data=want noobs;
run;

Result:

Name      IDnum

Amy        125 
Lily       652 
John       452 
Mark       123 
Amy        125 
Lily       652 
Amanda     452 
Mark       123 

Two variables.

 

San_0611
Calcite | Level 5
Where can I send this as a proof of answer?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 4736 views
  • 1 like
  • 5 in conversation