Get execution information from SAS

The code below makes a print to your log containing different information related to your current SAS-session.
The code is heavily inspired from this article.



Options in SASv9.cfg

The options below can be used to congfigure SAS through the file SASv9.cfg
The file is usually located in c:\program files\SAS\SASFoundation\9.2\nls\en\.
NB! Depending on your version of SAS.
You can find the installation directory for SASv9.cfg through the SAS GUI. Go to Tools -> System Options.


Option Description
-WORK w:\saswork\!username If the username for the users using SAS is eg APM this options creates a Work directory under w:\saswork\ called APM – w:\saswork\APM\. This makes it easier for the users to retrieve the tables in the work-directory and easier for system administration to locate users that takes up a lot of storage on the work-drive.
-odsdest=listing If you don’t like the default HTML-output. This option sets the output destination to listing. The output from SAS will now be shown like it used to.
 -odsgraphics=off If you don’t like the default HTML-output. This option will turn off ODS Graphics. The output from SAS will now be shown like it used to.
-MEMSIZE 4G Sets the maximum aout of RAM/memory that can be used during a SAS-session. In this case 4GB.
-SORTSIZE 2G Sets the maximum amount of RAM/memory that SORT procedure can use during a SAS-session. In this case 2GB.

Getting accessible schemas for a user

The code below gets the schemas from a Microsoft SQL-server that is accessible for a given user. It is made with SAS-code but the SQL-statement can be used regardless of using SAS.

Loop through datasets in SAS

This code was found here. It lets you loop through datasets in a SAS-library and tries to print the first 10 observations from each dataset in the SAS-library.


Call Execute lets you run PROC-statements in a datastep. It will simply execute the proc-statement after finishing the datastep. It is also possible to use ‘if‘, ‘then‘ and ‘else‘ in the datastep to execute certain parts of the code based on some value.
This is of course also possible through macro-code.

Writing a SAS-program in SAS

The code below will let you write a SAS-program in SAS.

/* This dummy macro-variable will be used later as input for the SAS program. */
%let HelloWorld = Hello world;
data _null_;
file SASProgram;
put ‘%let Hello='” &HelloWorld. “‘;’;
put ‘%put &Hello;’;
put ‘run;’;

filename cdrive “C:\SASPrograms”;

data _null_;
infile SASProgram;
file cdrive(;
put _infile_;
filename cdrive clear;

You now have a SAS-program called ‘‘ in the folder ‘C:\SASPrograms\‘.
The program will look like this.

%let Hello= Hello World;
%put &Hello;

And it will write ‘Hello World‘ to the log in SAS.

Signon to remote SAS

Below is an example of how you can signon to a remote SAS-server and execute SAS-commands.

/* Insert the name of the server that you want to connect to and the number of the port. It is usually 7551. The portnumber is the where your local SAS for the SAS/CONNECT service on the remote machine. */
%let remote=<Your server> 7551;
/* Gets your userid from the system and prompts you for your password when connecting. */
options comamid=tcp remote=remote; signon remote user=&sysuserid passwd=_prompt_;

/* Makes a libname for your workdirectory on the remote server. */
libname remtwork slibref=work server=remote;

/* The macro below is executed on the remote server and creates a libname for a userfolder on the remote server. The userfolder hos to have the same name as the macro &sysuserid. */
%macro UserLib;
%let user = %sysfunc(substr(&sysuserid,4));
libname &user.Lib “f:\users\&sysuserid”;
options compress=binary;

/* This creates a local libname that points to the user libname on the remote server. */
%let user = %sysfunc(substr(&sysuserid,4));
libname &user.Lib slibref=&user.Lib server=remote;


Below is shown how you can extract the current SVN revision number for a given path into SAS and use it in your SAS program.

You can now use the three diffent macrovariables called svnver1, svnver2 and svnver3 in your program.

You might also want to have a look at this blogpost regarding TFS.