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

Hi all,

I am wondering how to scan a series of values for each ID and generate a summary variable for each ID. Essentially, I need to look at all the tests each patient has had, and decide if they have ever been positive. The dataset I have is the following:

 

ID     Test Outcome

1         Positive

1         Positive

1         Negative

2         Negative

2         Negative

3         Negative

3         Negative

3         Positive

3         Negative

 

And I need one that looks like this:

ID     Test Outcome      Overall

1          Positive              Positive

1          Positive              Positive

1          Negative            Positive

2          Negative            Negative

2          Negative            Negative

2          Negative            Negative

3          Negative            Positive

3          Negative            Positive

3          Positive              Positive

3          Negative            Positive

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

There are many ways to do this one. 

 

If you're brand new to SAS, easiest approach is:

 

1. Sort on ID and DESCENDING test outcome

2. Use RETAIN to keep the first value across the ID. If it's POSITIVE it will be the first record because (P is after N alphabetically).

View solution in original post

2 REPLIES 2
Reeza
Super User

There are many ways to do this one. 

 

If you're brand new to SAS, easiest approach is:

 

1. Sort on ID and DESCENDING test outcome

2. Use RETAIN to keep the first value across the ID. If it's POSITIVE it will be the first record because (P is after N alphabetically).

stat_sas
Ammonite | Level 13

Hi,

 

Using proc sql:

 

proc sql;
create table want as
select *,case when sum(Test_Outcome="Positive")>0 then "Positive" else "Negative" end as Overall
from have group by id
order by id;
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 297 views
  • 0 likes
  • 3 in conversation