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

Hi All!

 

I have a dataset with 100+ date vairables and each observation may have 1 to 5 or so of those dates populated (all numeric date formats).  I need a way to select the max date from each observation...where the dates have no standard naming convention (all random names).  Can I do this with an array- or any other suggestion?  THis was my attempt...but clearly not working 🙂

 

data all1;
set all;
array dt (*) _numeric_;
do i= 1 to dim(dt);
date1 =max(dt(i));
end;
run;

 

Here is a snapshot of the data...by keep in mind there are 100+ off these dates with all different names

jenim514_1-1634918527061.png

 

Thak you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Are all the date variables side by side in the table?
If so you can reference them all at once by listing the first and last variable only:

max (of firstVar--lastVar);

If not, are they all SAS dates or do they all have the "DT" in the variable name? You can use a SQL step to query the SASHELP.VCOLUMNS table to create the list dynamically.

View solution in original post

2 REPLIES 2
Reeza
Super User
Are all the date variables side by side in the table?
If so you can reference them all at once by listing the first and last variable only:

max (of firstVar--lastVar);

If not, are they all SAS dates or do they all have the "DT" in the variable name? You can use a SQL step to query the SASHELP.VCOLUMNS table to create the list dynamically.
jenim514
Pyrite | Level 9
@Reeza yes they were side by side! Thank for the simple solution!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 959 views
  • 1 like
  • 2 in conversation