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!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 485 views
  • 1 like
  • 2 in conversation