Hello,
I have a dataset like this. 9 is Unknown and 1 is male 2 is female and 3 is both. so I would like to copy (not 9) values from gendersp in to gender_sp variable.
GENDER_SP | GENDERSP |
9 | 1 |
9 | 1 |
1 | 9 |
1 | 9 |
9 | 1 |
1 | 9 |
9 | 1 |
9 | 1 |
1 | 9 |
1 | 9 |
1 | 9 |
9 | 1 |
1 | 9 |
1 | 9 |
1 | 9 |
1 | 9 |
9 | 2 |
2 | 9 |
9 | 2 |
2 | 9 |
9 | 2 |
2 | 9 |
2 | 9 |
2 | 9 |
9 | 2 |
9 | 2 |
2 | 9 |
9 | 2 |
2 | 9 |
9 | 2 |
2 | 9 |
9 | 2 |
2 | 9 |
9 | 2 |
2 | 9 |
3 | 9 |
used this code.
if CL_PATIENTID="07898" AND CL_EVENTID="1151" AND GENDERSP="1" then GENDER_SP='1';
if CL_PATIENTID="25346" AND CL_EVENTID="1722" AND GENDERSP="1" then GENDER_SP='1';
if CL_PATIENTID="36391" AND CL_EVENTID="1442" AND GENDERSP="2" then GENDER_SP='2';
It did not work. Please help me find what is wrong. Thank you.
data want;
set have;
if gender_sp ne 9 then do;
gendersp = gender_sp;
end;
run;
@Dhana18 wrote:
Hello,
I have a dataset like this. 9 is Unknown and 1 is male 2 is female and 3 is both. so I would like to copy (not 9) values from gendersp in to gender_sp variable.
The section in orange above is unclear.
Please answer the following:
@Dhana18 wrote:
Hello,
I have a dataset like this. 9 is Unknown and 1 is male 2 is female and 3 is both. so I would like to copy (not 9) values from gendersp in to gender_sp variable.
GENDER_SP GENDERSP 9 1 9 1 1 9 1 9 9 1 1 9 9 1 9 1 1 9 1 9 1 9 9 1 1 9 1 9 1 9 1 9 9 2 2 9 9 2 2 9 9 2 2 9 2 9 2 9 9 2 9 2 2 9 9 2 2 9 9 2 2 9 9 2 2 9 9 2 2 9 3 9 used this code.
if CL_PATIENTID="07898" AND CL_EVENTID="1151" AND GENDERSP="1" then GENDER_SP='1'; if CL_PATIENTID="25346" AND CL_EVENTID="1722" AND GENDERSP="1" then GENDER_SP='1'; if CL_PATIENTID="36391" AND CL_EVENTID="1442" AND GENDERSP="2" then GENDER_SP='2';
It did not work. Please help me find what is wrong. Thank you.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.