Recoding several variables simultaneously in a dataset based on responses from another dataset

Reply
Occasional Contributor
Posts: 16

Recoding several variables simultaneously in a dataset based on responses from another dataset

Hi, I am mapping exposures from one data source to another data source. The issue I am having is that some exposures from one data source is aggregated creating a "nested scenario" with the other data source.  I am looking for a simplified approach to recoding several variables simultaneously.

For example,

Data source1                            Data source2

case_beef                                 caco_hamburger, caco_steak, caco_roastbeef

case_eggs                                caco_eggs, caco_scambegg,

case_dog                                  caco_dog

case_cat                                   caco_cat

The responses are Yes, No, or unknown.

Recoding exposures in data source2 based on data source1

If case_beef="YES" then I want all exposure variables from data source2="Yes";

If case_beef="NO" then ''                                                                            ="No";

....

Thank you in advance if you can help with this. Cara

Grand Advisor
Posts: 10,210

Re: Recoding several variables simultaneously in a dataset based on responses from another dataset

I think you should provide, preferably in the form of data step code we can run, examples of your two input data sets. Then show use what the output should look like.

Your current description doesn't reference variables, how the two data sets are to be combined or the values of actual dataset variables.

Occasional Contributor
Posts: 16

Re: Recoding several variables simultaneously in a dataset based on responses from another dataset

Included is a sample of a dataset I'm working on to map the case exposures in data source1 to case_exposures in data_source 2. I am working to create an appended dataset based on the exposure mapping. So for example, variables case _beef in data_source 1 will become variables caco_hamburger, caco_steak, caco_roastbeef in data_source2 (that will later become appended to data_source 2).

data_source1

Data sourcecase_beefcase_eggscase_have_dog
cs_caseYESYESNO
cs_caseUNKNOYES
cs_caseUNKYESUNK
cs_caseNONOUNK

data_source2

Data sourcecaco_hamburgercaco_steakcaco_roastbeefcaco_eggscaco_dog
caco_caseYESNONOYESYES
caco_caseNONOYESYESUNK
caco_caseUNKNOYESUNKYES
caco_controlUNKNOYESNOYES
caco_controlNOYESNOUNKNO

The final appended dataset will resemble

Data sourcecaco_hamburgercaco_steakcaco_roastbeefcaco_eggscaco_dog
caco_caseYESNONOYESYES
caco_caseNONOYESYESUNK
caco_caseUNKNOYESUNKYES
caco_controlUNKNOYESNOYES
caco_controlNOYESNOUNKNO
cs_caseYESYESYESYESNO
cs_caseUNKUNKUNKNOYES
cs_caseUNKUNKUNKYESUNK
cs_caseNONONONOUNK

Thank you

Frequent Contributor
Posts: 115

Re: Recoding several variables simultaneously in a dataset based on responses from another dataset

is this what you want?:

data final_appended;

set data_source2 data_source1(rename=(case_have_dog=caco_dog));

run;

Just edit yourself using the rename=dataset option in the set statement as many as you want.

Occasional Contributor
Posts: 16

Re: Recoding several variables simultaneously in a dataset based on responses from another dataset

Thank you Naveen. I was wondering if there was a simpler way that I was not aware of rather than repeating the variable mappings.

Ask a Question
Discussion stats
  • 4 replies
  • 179 views
  • 0 likes
  • 3 in conversation