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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 672 views
  • 0 likes
  • 3 in conversation