hello,
I have two dataset and I want to horizontal stacking them. the two dataset have same variable name but different rows. I would like to keep all cols and can add a_ , b_ in front of original col names. how can I achieve this?
data df_a; infile datalines dsd truncover; input id sex $ stop; datalines; 1,Female,0 1,M,1 1,Male,0 1,F,0 1,,1 ; data df_b; infile datalines dsd truncover; input id sex $ stop; datalines; 2,Female,0 1,M,1 1,Male,0 2,F,0 ;
there is no need to merge by id. just simply put two tables together. the output will look like below:
any suggestion?
/* below df_c will contain only 4 observations --> wrong */
data df_c;
set df_a(rename=(id=a_id sex=a_sex stop=a_stop));
set df_b(rename=(id=b_id sex=b_sex stop=b_stop));
run;
/* below df_c will contain 5 observations --> okay */
options MERGENOBY=WARN;
data df_c;
merge df_a(rename=(id=a_id sex=a_sex stop=a_stop))
df_b(rename=(id=b_id sex=b_sex stop=b_stop));
run;
/* end of program */
Koen
data want;
set df_a df_b;
run;
proc datasets library=work NoList NoDetails memtype=data;
delete want; run;
QUIT;
proc append base=want data=df_a; run;
proc append base=want data=df_b; run;
Koen
simple set statement will create vertical staking instead.
Oh sorry. You want horizontal stacking (instead of vertical).
PROC APPEND cannot do this.
Let me re-write.
Koen
/* below df_c will contain only 4 observations --> wrong */
data df_c;
set df_a(rename=(id=a_id sex=a_sex stop=a_stop));
set df_b(rename=(id=b_id sex=b_sex stop=b_stop));
run;
/* below df_c will contain 5 observations --> okay */
options MERGENOBY=WARN;
data df_c;
merge df_a(rename=(id=a_id sex=a_sex stop=a_stop))
df_b(rename=(id=b_id sex=b_sex stop=b_stop));
run;
/* end of program */
Koen
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.