Determine the version of SAS software at run time


Recently I wrote about how to determine the age of your SAS release. Experienced SAS programmers know that you can programatically determine information about your SAS release by using certain automatic macro variables that SAS provides:

  • SYSVER: contains the major and minor version of the SAS release
  • SYSVLONG: contains the information in SYSVER, and information about the maintenance release. For example, a value of 9.03.01M2D082312 means SAS 9.3m2.
  • SYSVLONG4: contains the information in SYSVLONG, and the year of release

For example, the following DATA step displays information about the SAS release. The results shown are for the second maintenance release of SAS 9.3.

SYSVER = 9.3
SYSVLONG = 9.03.01M2D082312
SYSVLONG4 = 9.03.01M2D08232012

These macro variables are usually used in macro code to conditionally include code (see the %INCLUDE statement) or to control the flow of execution through a macro, such as in the following example:

%if %sysevalf(&sysver < 9) %then %do;
   %put SAS 9.0 or later is required.  Terminating.;
   %goto exit;

Recently I wrote a SAS/IML function that decomposes the SYSVLONG macro into its components. You can write similar code for the SAS DATA step. The following program uses the FIND function and the SUBSTR function to parse and extract relevant information about a SAS release. If you ever have the need to extract details from the SYSVLONG macro variable, you might find this function helpful.

proc iml;
/* Helper function that returns information about the current SAS system release.
   This function decomposes the SYSVLONG system macro variable and returns four 
   numbers that are associated with the version.
start GetSASVersion( major, minor, iteration, maint );
   sysvlong = symget("SYSVLONG");                /* system macro variable */
   pos1 = find(sysvlong, ".");
   major = substr(sysvlong, 1, pos1-1);          /* major version */
   major = num(major);                           /* convert to numeric */
   pos2 = find(sysvlong, ".", 'i', pos1+1);
   minor = substr(sysvlong, pos1+1, pos2-pos1-1);/* minor version */
   minor = num(minor);
   pos3 = find(sysvlong, "M", 'i', pos2+1);
   iteration = substr(sysvlong, pos2+1, pos3-pos2-1);/* iteration version */
   iteration = num(iteration);
   pos4 = notdigit(sysvlong, pos3+1);
   maint = substr(sysvlong, pos3+1, pos4-pos3-1);   /* maintenance level */
   maint = num(maint);
/* test it by running code on SAS 9.3m2 (SAS/IML 12.1) */
run GetSASVersion( major, minor, iteration, maint );
v =  major || minor || iteration || maint;
print v[colname={"major" "minor" "iteration" "maint"} 
        label="Results for SAS 9.3m2"];
b = ( major<9 ) 
  | ( major=9 & minor<3 )
  | ( major=9 & minor=3 & iteration<1 )
  | ( major=9 & minor=3 & iteration=1 & maint<=2 );
if b then print "SAS 9.3m2 or earlier"; 
else      print "After SAS 9.3m2";

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.


  1. Peter Lancashire on

    I notice you wrote: /* test it by running code on SAS 9.3m2 (SAS/IML 12.1) */.

    Is it possible to determine the version of IML? Now that STAT is updated semi-independently, it would be useful for this component of SAS too.

    For audit purposes I would like to record in my output the version of the SAS component used, but I have not yet found a way to do it.

    Peter Lancashire

    • Rick Wicklin

      Every time that the advanced analytics products ship, it corresponds to a release of SAS. Thus there is a particular value for the SYSVLONG macro variable that corresponds to each release of SAS/STAT, SAS/IML, and so forth. As indicated, the 12.1 releases correspond to SAS 9.3m2.

  2. Pingback: Is ODS graphics enabled? Use automatic macro variables to determine the state of SAS - The DO Loop

Leave A Reply

Back to Top