BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
srmakwana2009
Fluorite | Level 6

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 DATEPK result 
10016-Mar-13Positive
10017-Mar-13Positive
10018-Mar-13Positive
10019-Mar-13Positive
10026-Mar-13Positive
10027-Mar-13Negative
10028-Mar-13Positive
10029-Mar-13Positive
100210-Mar-13Positive
10037-Mar-13Positive
10038-Mar-13Positive
10039-Mar-13Positive
100310-Mar-13Positive
100311-Mar-13Positive
10046-Mar-13Negative
10047-Mar-13Negative
10048-Mar-13Positive
10049-Mar-13Positive
100410-Mar-13Positive
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

2 REPLIES 2
Ksharp
Super User
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;
srmakwana2009
Fluorite | Level 6

Thank you so much. it worked

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