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.
Maxim 4: try it.
If it fails depends on the variable types. If they differ between the datasets, it'll crash.
another great option and this option helps us in learning. that is d) run the code with data you shown
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;
My question is How many variables are there in output data set , not the number of records or observations.
Thanks,
Sanika
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.
please check the below link
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm
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
@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.
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.