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

Dear All,

 

I have a dataset as below:

 

SUBJECT        OUTCOME

101                    FATAL

101                    RECOVERED

101                    FATAL

102                    NOT RECOVERED

102                    FATAL

103                    FATAL

103                    UNKNOWN

 

In the above dataset the subject (101) has outcome as fatal twice which is wrong as per our concept and other subjects (102 and 103) have OUTCOME as fatal only once as per concept. I have more than 100 records with different subject numbers. My requirement is to identify such subjects which have fatal more than once and flag them.

 

Any help ?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data want;
set have;
by subject,
retain _fatal;
if first.subject then _fatal = 0;
if outcome = "FATAL"
then do;
  if _fatal then result = "Yes";
  _fatal = 1;
end;
drop _fatal;
run;

Untested, posted from my tablet.

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26
proc freq data=have;
    tables subject*outcome/noprint out=want;
run;

This identifies the places where there are duplicates, because the value of variable COUNT in data set WANT will be > 1.

--
Paige Miller
r3570
Obsidian | Level 7

Dear Paigemiller,

Thanks for your swift response.

 

I do not need to count the duplicates but I just need to create a new column and flag the specific value like 'FATAL' as Yes or something so that it will be helpful for our analysis.. Could you please help how to write a prog for that ??

PaigeMiller
Diamond | Level 26

If you know which combinations have COUNT > 1 then you can use this to "flag" records (although I'm not really sure what you mean by that). Please show me your desired output.

 

 

--
Paige Miller
r3570
Obsidian | Level 7

My desired output should be as below:

 

SUBJECT        OUTCOME                     RESULT

101                    FATAL

101                    RECOVERED

101                    FATAL                             Yes

102                    NOT RECOVERED

102                    FATAL

103                    FATAL

103                    UNKNOWN

PaigeMiller
Diamond | Level 26

Does the final data set have to be in the order shown, or can we sort it?

--
Paige Miller
r3570
Obsidian | Level 7

sorting can be done by subject

Quentin
Super User

Are you familiar with by-group processing?  I would try something like (untested):

proc sort data=have;
  by subject outcome;
run;

data want;
  set have;
  by subject outcome;

  if first.outcome=0 and outcome="FATAL" then Result="Yes";
run;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Kurt_Bremser
Super User
data want;
set have;
by subject,
retain _fatal;
if first.subject then _fatal = 0;
if outcome = "FATAL"
then do;
  if _fatal then result = "Yes";
  _fatal = 1;
end;
drop _fatal;
run;

Untested, posted from my tablet.

r3570
Obsidian | Level 7

Output is not as expected. I cannot see the result variable populated as 'Yes' though there is repeated value in outcome for same subject

r3570
Obsidian | Level 7

Apologies..!!

out put is as expected. there was issue in case sensitive info...i rectified it.. thank you so much..!!

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
  • 10 replies
  • 1179 views
  • 0 likes
  • 4 in conversation