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

I have a dataset like below. There are 3 patients that visited the hospital multiple times, whether planned or unplanned. I would like to flag all the cases as planned = 1 once we find the first planned case.

 

data tr1;
input ptid$ day planned;
cards;
a 0 0
a 5 0
a 10 0
a 12 1
a 15 1
a 20 0
a 25 0
a 29 1
b 0 0
b 6 0
b 14 1
c 0 1
c 11 0
c 15 0
c 19 0
;
run;

 

I would like to have an output as below adding one extra flag. For ear patient (ptid) once it finds the first planed visit, I would like to have all the records after first planned visit as planned visit even if they are unplanned.

 

Thanks


ptid day planned plflag
a 0 0 0
a 5 0 0
a 10 0 0
a 12 1 1
a 15 1 1
a 20 0 1
a 25 0 1
a 29 1 1
b 0 0 1
b 6 0 1
b 14 1 1
c 0 1 1
c 11 0 1
c 15 0 1

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Assuming your example is wrong for pationt b :

 

data want;
do until(last.ptid);
    set tr1; by ptid;
    plFlag = plFlag or planned;
    output;
    end;
run;
PG

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21

Assuming your example is wrong for pationt b :

 

data want;
do until(last.ptid);
    set tr1; by ptid;
    plFlag = plFlag or planned;
    output;
    end;
run;
PG

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
  • 1 reply
  • 773 views
  • 1 like
  • 2 in conversation