Hello Community.
I need to create one variable where I have to derive if in PK sample for the particular subject has one or more Negative result then create new variable ADAT and give value =1. Following is example of data.
Please guide what to write in code to get that value. It's urgent need help ASAP
Subject | DATE | PK result |
1001 | 6-Mar-13 | Positive |
1001 | 7-Mar-13 | Positive |
1001 | 8-Mar-13 | Positive |
1001 | 9-Mar-13 | Positive |
1002 | 6-Mar-13 | Positive |
1002 | 7-Mar-13 | Negative |
1002 | 8-Mar-13 | Positive |
1002 | 9-Mar-13 | Positive |
1002 | 10-Mar-13 | Positive |
1003 | 7-Mar-13 | Positive |
1003 | 8-Mar-13 | Positive |
1003 | 9-Mar-13 | Positive |
1003 | 10-Mar-13 | Positive |
1003 | 11-Mar-13 | Positive |
1004 | 6-Mar-13 | Negative |
1004 | 7-Mar-13 | Negative |
1004 | 8-Mar-13 | Positive |
1004 | 9-Mar-13 | Positive |
1004 | 10-Mar-13 | Positive |
data have;
infile cards expandtabs;
input (Subject DATE PK_result) (: $20.);
cards;
1001 6-Mar-13 Positive
1001 7-Mar-13 Positive
1001 8-Mar-13 Positive
1001 9-Mar-13 Positive
1002 6-Mar-13 Positive
1002 7-Mar-13 Negative
1002 8-Mar-13 Positive
1002 9-Mar-13 Positive
1002 10-Mar-13 Positive
1003 7-Mar-13 Positive
1003 8-Mar-13 Positive
1003 9-Mar-13 Positive
1003 10-Mar-13 Positive
1003 11-Mar-13 Positive
1004 6-Mar-13 Negative
1004 7-Mar-13 Negative
1004 8-Mar-13 Positive
1004 9-Mar-13 Positive
1004 10-Mar-13 Positive
;
proc sql;
create table want as
select *,ifn(sum(PK_result='Negative'),1,0) as ADAT
from have
group by Subject;
quit;
data have;
infile cards expandtabs;
input (Subject DATE PK_result) (: $20.);
cards;
1001 6-Mar-13 Positive
1001 7-Mar-13 Positive
1001 8-Mar-13 Positive
1001 9-Mar-13 Positive
1002 6-Mar-13 Positive
1002 7-Mar-13 Negative
1002 8-Mar-13 Positive
1002 9-Mar-13 Positive
1002 10-Mar-13 Positive
1003 7-Mar-13 Positive
1003 8-Mar-13 Positive
1003 9-Mar-13 Positive
1003 10-Mar-13 Positive
1003 11-Mar-13 Positive
1004 6-Mar-13 Negative
1004 7-Mar-13 Negative
1004 8-Mar-13 Positive
1004 9-Mar-13 Positive
1004 10-Mar-13 Positive
;
proc sql;
create table want as
select *,ifn(sum(PK_result='Negative'),1,0) as ADAT
from have
group by Subject;
quit;
Thank you so much. it worked
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!
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.