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

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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