BookmarkSubscribeRSS Feed
Katie
Obsidian | Level 7

I have data that looks like this:

Patient          ProgramDate         FinanceDate

A                    1/1/2012                    2/3/2012

A                      2/5/2012                    4/6/2012

A                         .                         5/25/2012

B                      2/1/2012               4/1/2012

B                         .                              4/5/2012

The data needs to look like this:

Patient          VisitDates

A                    1/1/2012

A                    2/5/2012

A                    4/6/2012

A                     5/25/2012

B                     2/1/2012

B                    4/1/2012

B                    4/5/2012

Basically I need the Finance Date to match up to a Program Date.  No Finance Dates are allowed to Match up to the earliest ProgramDate.  The finance date can be counted for in the Program Date if it occurs prior to a singular date.  This is why Patient A does not have a VisitDate for 2/3/2012.  This one is 'counted' twice and we only need to show one date.

1 REPLY 1
mohamed_zaki
Barite | Level 11

data have;

input Patient $ ProgramDate: mmddyy10. FinanceDate: mmddyy10.;

cards;

A 1/1/2012 2/3/2012

A 2/5/2012 4/6/2012

A . 5/25/2012

B 2/1/2012 4/1/2012

B . 4/5/2012

;

run;

data want (keep=Patient VisitDate);

set have;

x=lag(FinanceDate);

rename ProgramDate=VisitDate;

if ProgramDate=. then do;

    ProgramDate=x ;

        output;

    ProgramDate=FinanceDate;

        output;

end;

else output;

run;

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