BookmarkSubscribeRSS Feed
bananah13
Fluorite | Level 6

Hello,

I have a SQL to SAS program that must be run monthly. I recently used EG to automate the process at the beginning of each month so I don't have to remember to go in and manually run it each month, which is working great.

 

Part of the QC process for the monthly run is to save the SAS program with the run date (to keep track of any program changes). Is there code I could put in my program that would automatically save it? I tried to proc export the .sas program, but it looks like you can only export datasets. Ideas? 

3 REPLIES 3
SASKiwi
PROC Star

Keeping track of program changes is best done with a versioning tool rather than doing it yourself manually. EG supports the use of GIT for version control.

 

You can find out more here: SAS Help Center: About Git Integration in SAS Enterprise Guide

Kurt_Bremser
Super User

Tracking of code has to be done in a proper code management tool, like git or svn or (insert gazillion of others).

To keep a documentation of how data was built, keep the logs. Make sure that the runtime is included properly in the logfile name (YYYYMMDDHHMMSS), so that each run gets its own log.

Proper automation of code needs to be done server-side, not from EG. Save your whole code as a .sas file to the server, and set up batch execution of the code there. Depending on your needs, crontab may suffice, but using a dedicated scheduling tool is preferred, especially if your company/organization already has one.

Patrick
Opal | Level 21

@bananah13 

For a really production worthy version of what you're doing you would use a scheduler to run your code in batch.

Others already commented how to manage code changes and that this requires a version control tool if done seriously.

 

Now... IF you want to store the SAS code executed at a specific point in time after all SAS macro logic and macro variables have been resolved then you could use and approach like below.

%macro wrapper();
  /** here your current program */

  %let month_key=%sysfunc(intnx(month,%sysfunc(date()),0,b),yymmn6.);
  data test_&month_key;
    set sashelp.class;
  run;

  /** here the end of your current program **/
%mend;

/** this bit new to execute the macro and capture the generated SAS code **/
filename mprint "c:\temp\myprog_run_%sysfunc(datetime(),B8601DT.).sas";
options mprint mfile;
%wrapper();
options nomfile;
/*filename mprint clear;*/
/** end of new code section **/

/** this bit just for the question here to print the generated code **/
data _null_;
  file print;
  infile mprint;
  input;
  put _infile_;
run;
filename mprint clear;

Patrick_0-1649150527519.png

You basically wrap a SAS macro around all of your code and then store the generated SAS code by this macro in an external file with a datestamp.

 

Above is NOT a replacement for version control but a way to collect generated SAS code in a way that's easier to read (and re-execute) than what you get in the SAS log.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 783 views
  • 1 like
  • 4 in conversation