BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

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_SPGENDERSP
91
91
19
19
91
19
91
91
19
19
19
91
19
19
19
19
92
29
92
29
92
29
29
29
92
92
29
92
29
92
29
92
29
92
29
39

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.

3 REPLIES 3
maguiremq
SAS Super FREQ
data want;
set have;
if gender_sp ne 9 then do;
	gendersp = gender_sp;
end;
run;
Dhana18
Obsidian | Level 7
I tried the code you sent. The log shows no problem and I checked with one of the id 07898 using proc print. Same patient can have two visits so this is what I see in the output
CL_PATIENTID

CL_EVENTID

VISDATE

GENDER_SP

GENDERSP

16

07898

1073

2019-07-26

1

1

17

007898

1151

2019-07-30

9

1













It did not work.
Reeza
Super User

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

  • You're starting with variable gendersp?
  • Does gender_sp variable already exist in the data set?
  • If not, you're creating it from gendersp, what are the rules: How do you know when to put a 1 or 2?
  • If it's by ID, as you seem to indicate in your code, how do you know that, do you have a list of IDs somewhere?
Spoiler

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


 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 751 views
  • 1 like
  • 3 in conversation