BookmarkSubscribeRSS Feed
mrug12
Calcite | Level 5


i have dataset as below

no   x   y    z    date               month        year

1    a               05/02/2012     5/12         2012

1    b               07/02/2012      07/12       2012

1        a           03/02/2012      3/12         2012

1               a    04/04/2012      04/12      2012

1  a                 05/02/2011       5/12       2011

now i want to convert in following way

no    x    y    z     year

1     b    a   a      2012

1    a                 2011

what logic need to apply here?  

as i have to keep most recent record as per date for year for client no and need to keep most recent values for x y z.

1 REPLY 1
Astounding
PROC Star

First, sort to get the data in order.  This BY statement might be overkill, because I'm not sure if DATE is character or actually represents a SAS date.  It will work either way, however, AS LONG AS YOUR MONTH values are consistent.  You can't store month with leading zeros just some of the time.  You need to have them or omit them consistently, to get the right order:

proc sort data=have;

by no year month date;

run;

Then to get the most recent values:

data want;

   update have (obs=0) have;

   by no year;

   drop date month;

run;

I have to give credit somewhere, but I'm not sure to whom.  A similar solution had been proposed to a similar question at some point.

Good luck.

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
  • 530 views
  • 4 likes
  • 2 in conversation