BookmarkSubscribeRSS Feed
RAVI2000
Lapis Lazuli | Level 10

How to print non-consecutive / consecutive dates from given set of dates?

Data x;
Input patid date mmddyy10.;
Datalines;
1001 02/01/10
1001 02/02/10
1001 02/03/10
1002 02/01/10
1002 02/03/10
1002 02/05/10
;
Run;

Can anyone explain the detailed logic step by step?

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
What is your desired resultat here?
mkeintz
PROC Star

This might be a good situation to use the DIF function, where  dif(x) is equivalent to x - lag(x):

data want;
  set have;
  by patid;
  if first.patid=0 and dif(date)=1 then consecutive='Y';
  else consecutive='N';
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 650 views
  • 0 likes
  • 4 in conversation