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

Hi

 

I would like to automatically set the dataset with the newest date.

 

My problem is the following:

 

I have a folder / directory which contains datasets with a date in the file name. The date indicates when the dataset is generated. It could for instance be called a_08AUG16 or a_09AUG16. I want to be able to set the latest dataset automatically based on the date in the file name. Is that possible?

 

Best regards

 

Aske

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Let me start by saying its never a good idea to put "data" into the structural part of the dataset - either table details or column details, it makes programming so much harder, and runs up problems like this.  Put data in the rows of the dataset.

 

Now you can use the metadata files from sashelp.vtable, basically that has the structural parts as data elements.  

data _20JAN2016;
  set sashelp.class;
run;
data _14FEB2016;
  set sashelp.cars;
run;

proc sql noprint;
  select  put(max(DTE),date9.)
  into    :DTE
  from    (select *,input(strip(compress(MEMNAME,"_","")),date9.) as DTE from SASHELP.VTABLE where libname="WORK" and substr(MEMNAME,1,1)="_");
quit;

data want;
  set work._&DTE.;
run;

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Let me start by saying its never a good idea to put "data" into the structural part of the dataset - either table details or column details, it makes programming so much harder, and runs up problems like this.  Put data in the rows of the dataset.

 

Now you can use the metadata files from sashelp.vtable, basically that has the structural parts as data elements.  

data _20JAN2016;
  set sashelp.class;
run;
data _14FEB2016;
  set sashelp.cars;
run;

proc sql noprint;
  select  put(max(DTE),date9.)
  into    :DTE
  from    (select *,input(strip(compress(MEMNAME,"_","")),date9.) as DTE from SASHELP.VTABLE where libname="WORK" and substr(MEMNAME,1,1)="_");
quit;

data want;
  set work._&DTE.;
run;

 

Kurt_Bremser
Super User

The best solution, hands down, is to use a date format in the dataset names that sorts itself, ie YYYY-MM-DD.

With the current situation, you will have to read the dataset names from sashelp.vtable (or dictionary.tables), convert the date in the dataset name to a SAS date, and retrieve the wanted observation with max(date).

Aske
Calcite | Level 5

Thanks for the help!

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
  • 3 replies
  • 1656 views
  • 1 like
  • 3 in conversation