Questions Regarding Combining Datasets Using the "Set" Statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Questions Regarding Combining Datasets Using the "Set" Statement

When you combine datasets using the "set" statement, do the variables in each of the datasets have to correspond to each other? In other words, do the same variables have to have the same name? For example, if the variable for systolic blood pressure at baseline is sbp in one dataset, would I have to name the variable for systolic blood pressure for another dataset sbp, even if it's the systolic blood pressure at follow-up? Thanks! 


Accepted Solutions
Solution
‎06-06-2018 02:16 PM
PROC Star
Posts: 1,799

Re: Questions Regarding Combining Datasets Using the "Set" Statement

Please review this thoroughly, you will understand:

 

data one;
set sashelp.class;
run;

data two;
set sashelp.class;
run;
title 'append with same_varnames';
data same_varnames;
set one two;
run;
proc print data=same_varnames;run;
title ;
/*rename to make it different*/
data two;
set sashelp.class;
rename height=ht;
run;
title 'append with diff_varname';
data diff_varname;
set one two;
run;
proc print data=diff_varname;run;

 

Outputs:

 

SAS Output

append with same_varnames

Obs Name Sex Age Height Weight1234567891011121314151617181920212223242526272829303132333435363738
AlfredM1469.0112.5
AliceF1356.584.0
BarbaraF1365.398.0
CarolF1462.8102.5
HenryM1463.5102.5
JamesM1257.383.0
JaneF1259.884.5
JanetF1562.5112.5
JeffreyM1362.584.0
JohnM1259.099.5
JoyceF1151.350.5
JudyF1464.390.0
LouiseF1256.377.0
MaryF1566.5112.0
PhilipM1672.0150.0
RobertM1264.8128.0
RonaldM1567.0133.0
ThomasM1157.585.0
WilliamM1566.5112.0
AlfredM1469.0112.5
AliceF1356.584.0
BarbaraF1365.398.0
CarolF1462.8102.5
HenryM1463.5102.5
JamesM1257.383.0
JaneF1259.884.5
JanetF1562.5112.5
JeffreyM1362.584.0
JohnM1259.099.5
JoyceF1151.350.5
JudyF1464.390.0
LouiseF1256.377.0
MaryF1566.5112.0
PhilipM1672.0150.0
RobertM1264.8128.0
RonaldM1567.0133.0
ThomasM1157.585.0
WilliamM1566.5112.0

 


append with diff_varname

Obs Name Sex Age Height Weight ht1234567891011121314151617181920212223242526272829303132333435363738
AlfredM1469.0112.5.
AliceF1356.584.0.
BarbaraF1365.398.0.
CarolF1462.8102.5.
HenryM1463.5102.5.
JamesM1257.383.0.
JaneF1259.884.5.
JanetF1562.5112.5.
JeffreyM1362.584.0.
JohnM1259.099.5.
JoyceF1151.350.5.
JudyF1464.390.0.
LouiseF1256.377.0.
MaryF1566.5112.0.
PhilipM1672.0150.0.
RobertM1264.8128.0.
RonaldM1567.0133.0.
ThomasM1157.585.0.
WilliamM1566.5112.0.
AlfredM14.112.569.0
AliceF13.84.056.5
BarbaraF13.98.065.3
CarolF14.102.562.8
HenryM14.102.563.5
JamesM12.83.057.3
JaneF12.84.559.8
JanetF15.112.562.5
JeffreyM13.84.062.5
JohnM12.99.559.0
JoyceF11.50.551.3
JudyF14.90.064.3
LouiseF12.77.056.3
MaryF15.112.066.5
PhilipM16.150.072.0
RobertM12.128.064.8
RonaldM15.133.067.0
ThomasM11.85.057.5
WilliamM15.112.066.5

 

View solution in original post


All Replies
Solution
‎06-06-2018 02:16 PM
PROC Star
Posts: 1,799

Re: Questions Regarding Combining Datasets Using the "Set" Statement

Please review this thoroughly, you will understand:

 

data one;
set sashelp.class;
run;

data two;
set sashelp.class;
run;
title 'append with same_varnames';
data same_varnames;
set one two;
run;
proc print data=same_varnames;run;
title ;
/*rename to make it different*/
data two;
set sashelp.class;
rename height=ht;
run;
title 'append with diff_varname';
data diff_varname;
set one two;
run;
proc print data=diff_varname;run;

 

Outputs:

 

SAS Output

append with same_varnames

Obs Name Sex Age Height Weight1234567891011121314151617181920212223242526272829303132333435363738
AlfredM1469.0112.5
AliceF1356.584.0
BarbaraF1365.398.0
CarolF1462.8102.5
HenryM1463.5102.5
JamesM1257.383.0
JaneF1259.884.5
JanetF1562.5112.5
JeffreyM1362.584.0
JohnM1259.099.5
JoyceF1151.350.5
JudyF1464.390.0
LouiseF1256.377.0
MaryF1566.5112.0
PhilipM1672.0150.0
RobertM1264.8128.0
RonaldM1567.0133.0
ThomasM1157.585.0
WilliamM1566.5112.0
AlfredM1469.0112.5
AliceF1356.584.0
BarbaraF1365.398.0
CarolF1462.8102.5
HenryM1463.5102.5
JamesM1257.383.0
JaneF1259.884.5
JanetF1562.5112.5
JeffreyM1362.584.0
JohnM1259.099.5
JoyceF1151.350.5
JudyF1464.390.0
LouiseF1256.377.0
MaryF1566.5112.0
PhilipM1672.0150.0
RobertM1264.8128.0
RonaldM1567.0133.0
ThomasM1157.585.0
WilliamM1566.5112.0

 


append with diff_varname

Obs Name Sex Age Height Weight ht1234567891011121314151617181920212223242526272829303132333435363738
AlfredM1469.0112.5.
AliceF1356.584.0.
BarbaraF1365.398.0.
CarolF1462.8102.5.
HenryM1463.5102.5.
JamesM1257.383.0.
JaneF1259.884.5.
JanetF1562.5112.5.
JeffreyM1362.584.0.
JohnM1259.099.5.
JoyceF1151.350.5.
JudyF1464.390.0.
LouiseF1256.377.0.
MaryF1566.5112.0.
PhilipM1672.0150.0.
RobertM1264.8128.0.
RonaldM1567.0133.0.
ThomasM1157.585.0.
WilliamM1566.5112.0.
AlfredM14.112.569.0
AliceF13.84.056.5
BarbaraF13.98.065.3
CarolF14.102.562.8
HenryM14.102.563.5
JamesM12.83.057.3
JaneF12.84.559.8
JanetF15.112.562.5
JeffreyM13.84.062.5
JohnM12.99.559.0
JoyceF11.50.551.3
JudyF14.90.064.3
LouiseF12.77.056.3
MaryF15.112.066.5
PhilipM16.150.072.0
RobertM12.128.064.8
RonaldM15.133.067.0
ThomasM11.85.057.5
WilliamM15.112.066.5

 

Occasional Contributor
Posts: 13

Re: Questions Regarding Combining Datasets Using the "Set" Statement

Posted in reply to novinosrin

Thanks so much! 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 96 views
  • 2 likes
  • 2 in conversation