BookmarkSubscribeRSS Feed
IplaywithSAS
Calcite | Level 5

Hello,

 

I very recently started using SAS and one of the daily tasks I have is basically go through every single project and update the primary tables and run the project.

I was wondering if there is a way to automatically run the project with the most recent table available, for example:

 

I have table Cars_2021_09_01 where the project is collecting data. So since the month changed a new table was created name Cars_2021_10_01. Currently I have to open the project and manually change the previous table with the new table. Is there a way to do that automatically? 

 

Thanks for the help 🙂

2 REPLIES 2
SASKiwi
PROC Star

Is the date you want to process related to the date you run the project? For example if you run your project during September you want to read Cars_2021_09_01 and if you run during October you want Cars_2021_10_01? If so you can make use of the SAS TODAY function to read today's date and then automatically read the table you want.

data _null_;
  Table_Name = 'Cars_' !! translate(put(intnx('MONTH',today(), 0, 'BEGIN'), yymmddd10.), '_', '-');
  put _all_;
run;

 

Kurt_Bremser
Super User

So you have a library where all those datasets reside. Let's call this library IN for the example.

Within that library you have several datasets starting with CARS_, thankfully sorted by date because you use (commendable!) a YMD order.

Basically, you can retrieve the name of the most recent dataset like this:

proc sql noprint;
select max(name) into :dsname
from dictionary.tables
where libname = "IN" and memname like 'CARS_%';
quit;

After that use &dsname. wherever you need the source dataset.

 

Note that libname and memname in the dictionary tables are always uppercase for SAS datasets/views.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 991 views
  • 0 likes
  • 3 in conversation