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;
BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.
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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 974 views
  • 0 likes
  • 4 in conversation