Monday, January 15, 2018

Hack 7.2 Capturing the Values of Windows Environmental Variables




SAS Programming Professionals,

Did you know that you can capture the name and value of Windows environmental variables with SAS?

Environmental variables are a class of variables created by the operating system to store values used by a wide variety of programs.  For example, the TEMP variable holds the value of the directory that all programs should use when creating temporary files.  On the Windows 7 workstation I am currently using, that value is C:\Users\Michael\AppData\Local\Temp.

Here is a very straight-forward program you can use to identify the Windows environmental variables and their values:

filename enviovar pipe 'set' lrecl=1024;

data work.xpset;

infile enviovar dlm='=' missover;

length name $ 32 value $ 100;

input name $ value $;

run;

proc print noobs;
title1 "Windows Environmental Variables for My Workstation";
run;
If you take a moment to run that program, you will find a fascinating array of environmental variables available to you. You can see the directory common programs are stored in, the path to your home directory, the number of processors your computer has, the processor architecture, the user name, and the directory where the user profile is stored.

You can capture and then use the Windows environmental variables in your SAS programs where you need to identify something particular to a Windows workstation or PC.  Or, you might choose to dump them into a flat file as a means of documenting the exact system that you were running SAS programs on—say in a clinical trials environment.  The Windows environmental variables are there for the using.  So, go ahead and use them!


The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers
https://tinyurl.com/y83aleb4

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

No comments:

Post a Comment