BookmarkSubscribeRSS Feed
VincentLe
Calcite | Level 5

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.

7 REPLIES 7
ChrisBrooks
Ammonite | Level 13

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...

VincentLe
Calcite | Level 5

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. 

Astounding
PROC Star

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;

Reeza
Super User

INDSNAME option, example and documentation here:

http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=p00hxg3x8lwivcn1f0e9axziw57y.htm&docs...


@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.


 

VincentLe
Calcite | Level 5

Thank for your link, but it doesn't tell me how to create dummy variables to identify data set later. 

Reeza
Super User

@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?

Patrick
Opal | Level 21

@VincentLe

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 964 views
  • 0 likes
  • 5 in conversation