BookmarkSubscribeRSS Feed
lca
Calcite | Level 5 lca
Calcite | Level 5

Hello!

SAS newbie here 🙂

I have table similar to this:

ID
Version
Value
100010
100111
200020
200121
200222
200321
200420
300040
300141
300243

I want to extract data and make a new table with only unique IDs with the highest version and corresponding value.

Like this:

ID
Version
Value
100111
200420
300243

This is may be easy, but I'm new to SAS 🙂

Any suggestions?


4 REPLIES 4
art297
Opal | Level 21

There are a number of ways.  Here is one using proc sort.

proc sort data=have;

  by id descending version;

run;

proc sort data=have out=want nodupkey;

  by id;

run;

lca
Calcite | Level 5 lca
Calcite | Level 5

Thank you, it worked Smiley Happy

art297
Opal | Level 21

You could also do it using proc sql:

proc sql noprint;

  create table want as

     select *

       from have

         group by id

           having version eq max(version)

  ;

quit;

DLing
Obsidian | Level 7

The data set also appears to be sorted by ID and Version, in which case, you can use:

proc sort data=have;   *--- only needed if not already sorted by ID and Version;

   by id version;

run;

data want;

   set have;

   by id;

   if last.id;   *--- highest version for each id due to sorting;

run;

Use which ever method you find more natural and intuitive to you.  Art's methods all work.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 722 views
  • 0 likes
  • 3 in conversation