BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zimcom
Pyrite | Level 9

Hi Greetings!!

 

I have:

SubjectVisit IdScorealive
1005100Yes
1005402Yes
1005502Yes
100560.Yes
100580.Yes
1006100Yes
1006400Yes
1006502Yes
100660.Yes
100680.Yes
1010100No
101040.No
101050.No
101060.No
101080.No
1008100Yes
100840.Yes
100850.Yes
100860.Yes
100880.Yes
1009100Yes
1009404Yes
100950.Yes
100960.Yes
100980.Yes

 

I want impute Score of 100 when "alive" is "No" for that subject (differences highlighted):

SubjectVisit IdScorealive
1005100Yes
1005402Yes
1005502Yes
100560.Yes
100580.Yes
1006100Yes
1006400Yes
1006502Yes
100660.Yes
100680.Yes
1010100No
101040100No
101050100No
101060100No
101080100No
1008100Yes
100840.Yes
100850.Yes
100860.Yes
100880.Yes
1009100Yes
1009404Yes
100950.Yes
100960.Yes
100980.Yes
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Do you mean:

if alive = 'No' and missing(score) then score = 100;

View solution in original post

13 REPLIES 13
PaigeMiller
Diamond | Level 26

I am not sure I grasp the full meaning of

 

I want impute Score of 100 when "alive" is "No" for that subject (differences highlighted):

Based on your example, this seems to be the same as: I want impute Score of 100 when "alive" is "No" 

 

and no reference to "for that subject" is needed. What am I missing?

--
Paige Miller
zimcom
Pyrite | Level 9

I only want to impute the score "100" for the specific subject though (in above example, it is subject 1010)

Shmuel
Garnet | Level 18

Do you mean:

if alive = 'No' and missing(score) then score = 100;
zimcom
Pyrite | Level 9
I only want to impute the score "100" for the specific subject though (in above example, it is subject 1010)
alpine_nights
Fluorite | Level 6

Adding onto Shmuel's code:

If you want it for that specific subject, all you have to add is this

if alive = 'No' and missing(score) and Subject='1010' then score = 100;

If there are multiple subjects you want to do that for, use an in statement with whatever subject you want

if alive = 'No' and missing(score) and Subject in ('1010','1200') then score = 100;

 

zimcom
Pyrite | Level 9

I have hundreds of subjects and I cannot hard coded the subject like this, I need this to be automated

Subject='1010'
Subject in ('1010','1200') 

 

 

alpine_nights
Fluorite | Level 6

What is your criteria for which subjects need to be changed? I don't think we are understanding fully what needs to be done. Maybe you could give another example?

Shmuel
Garnet | Level 18

If I understand you correctly then you need to add the appropriate condition:

if subject = 1010 and alive = 'No' and missing(score) then score = 100;
zimcom
Pyrite | Level 9

Sorry, probably I wasn't clear, each subject has multiple Visit, and when the alive is "No", I want to impute the Score of "100" to the Score of each Visit of that subject.

I cannot hard code the subject using "subject = "1010", I have hundreds of subject and I want this be automated.

 

Thank you all for your reply, but still did not solve my problem.

alpine_nights
Fluorite | Level 6

Hmm, I do not believe I understand still.

Could you tell us what is not working with Shmuels's original code:

if alive = 'No' and missing(score) then score = 100;

If you want every score replaced, includes ones that were already there, just remove the missing(score), but the above code does create the output in red you showed. If you describe what this is doing wrong/what else you would like we can help more.

zimcom
Pyrite | Level 9

if alive = 'No' then (for that suject), all the Score (of each Visit) = '100';

PaigeMiller
Diamond | Level 26

Another question: if a subject has alive='No', can they also have alive='Yes' elsewhere in the data?

 

Can you modify your original example to make it more relevant to what has been discussed? (Providing a good example helps you get faster answers)

--
Paige Miller
zimcom
Pyrite | Level 9
Another question: if a subject has alive='No', can they also have alive='Yes' elsewhere in the data?
No, if subject died, then alive will be all as "No" for that subject.

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
  • 13 replies
  • 2300 views
  • 2 likes
  • 4 in conversation