Help using Base SAS procedures

Dummy Variables To Identify A Data Set Later

Reply
New Contributor
Posts: 3

Dummy Variables To Identify A Data Set Later

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.

Valued Guide
Posts: 595

Re: Dummy Variables To Identify A Data Set Later

Posted in reply to VincentLe

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

New Contributor
Posts: 3

Re: Dummy Variables To Identify A Data Set Later

Posted in reply to ChrisBrooks

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. 

Super User
Posts: 6,785

Re: Dummy Variables To Identify A Data Set Later

Posted in reply to VincentLe

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;

Super User
Posts: 23,776

Re: Dummy Variables To Identify A Data Set Later

Posted in reply to VincentLe

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.


 

New Contributor
Posts: 3

Re: Dummy Variables To Identify A Data Set Later

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

Super User
Posts: 23,776

Re: Dummy Variables To Identify A Data Set Later

Posted in reply to VincentLe

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?

Respected Advisor
Posts: 4,741

Re: Dummy Variables To Identify A Data Set Later

Posted in reply to VincentLe

@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;
Ask a Question
Discussion stats
  • 7 replies
  • 186 views
  • 0 likes
  • 5 in conversation