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 🙂
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;
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.