Hi all,
Before I combine 2 data sets, NLSY79 and NLSY97 together, I want to create dummy variables indicating which data NLSY79 is and which NLSY97 is. How do I create these dummy variable for each of these data set? Any idea is appreciated. Have a great day!
Vincent.
It depends how you want to combine them - do you want to merge them or append them?
It would be helpful if you could give samples of the input and output data sets...
Hi Chris,
Thank you for your response. I just want to append (stack) one on another.
Here is an example. The first input data set is NLSY79 that has 25 original variables. The second input data set is NLSY97 that has 25 original variables. So I would run: Data NLSY79andNLSY97; Set NLSY79 NLSY97;
The output data is NLSY79andNLSY97.
However, after combining these 2 data sets, I'd like to run a logistic model on both data set with a interaction term to be added on NLSY97 only. So I need to give SAS a signal that add an interaction term on NLSY97 only and not on both. That is why I need dummy variables that identify NLSY97 before I combine it with NLSY79. But I don't know who to make those dummy variables on each data set.
I hope this make it clearer. If not, I can explain more.
Thanks.
Simplest would be to take your program, and add the pieces in red:
data NLSY79andNLSY97;
set NLSY79 NLSY97 (in=flag_these);
from_NLSY97 = flag_these;
run;
INDSNAME option, example and documentation here:
@VincentLe wrote:
Hi all,
Before I combine 2 data sets, NLSY79 and NLSY97 together, I want to create dummy variables indicating which data NLSY79 is and which NLSY97 is. How do I create these dummy variable for each of these data set? Any idea is appreciated. Have a great day!
Vincent.
Thank for your link, but it doesn't tell me how to create dummy variables to identify data set later.
@VincentLe wrote:
Thank for your link, but it doesn't tell me how to create dummy variables to identify data set later.
Did your run the sample code and look at the output?
Using data set options in= or indsname= are very valid options and both will work.
As an alternative code as below should do the job as well.
proc sql;
create table want as
select *, 'ds1' as source
from sashelp.class
union corr all
select *, 'ds2' as source
from sashelp.class
;
quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.