Add Health: Mapping Temp Files to Server Scratch Space

Statistical packages normally create temporary files on a local hard drive. These notes describe how Windows users should redirect temporary files to scratch space on a restricted data server - in this case the one on which the National Longitudinal Study of Adolescent Health (Add Health) data resides. These operations are only possible and relevant to individuals that have been authorized for use of the data.

Initial Drive Mapping

The Add Health data are mapped to a drive letter of one's choosing using the Start > Computer > Map network drive facility.

The figure below illustrates mapping to drive letter Z: with the Connect using different credentials box checked.


Subsequently you are prompted for credentials, which must match those for your account on server role.


Successful mapping results display of the top-level directory listing.


In the above listing:


Redefining temp space in SAS involves redefining the location of the WORK library, which is specified in the SAS configuration file. It is not possible to override the setting after SAS is invoked, so it is necessary to invoke SAS with an alternate configuration file.

For purposes of this example illustrated using SAS 9.3, the default SAS config file is located in:

C:\Program Files\SASHome\SASFoundation\9.3\nls\en\sasv9.cfg

Go to this location, right-click the file and copy it. Navigate to a location within your profile where you can place a copy of the file. In my case I selected:

C:\Users\bobj\My Documents\My SAS Files\9.3

Right-click and paste the file.

While not necessary, you may want to change the name of the file to something like sasv9_adhealth.cfg that is suggestive of its purpose.

Open with a text editor (such as Notepad) and find the -WORK specification toward the bottom. Comment it out with a leading /* and trailing */. Add a new specification as shown below, where the drive letter matches the one you use to map the Add Health server. Save the new specification.

/*-WORK "!TEMP\SAS Temporary Files"*/
-WORK "Z:\scratch"

Using the Windows Start menu, navigate to the SAS executable. Right click on it and copy the program icon. Paste the icon to your desktop. Click on the icon label and rename it something useful to indicate this will be an alternate invocation for SAS, such as SAS 9.3 AdHealth.

Right-click on the icon and select the Properties option. Select the Shortcut tab. Modify the Target entry to reflect the location and name of the alternate SAS configuration file you have created. For this example, the entry becomes:

"C:\Program Files\SASHome\SASFoundation\9.3\sas.exe" -CONFIG "C:\Users\bobj\My Documents\My SAS Files\9.3\sasv9_adhealth.cfg"

Apply the change and close the icon configuration.

Test the new icon. If SAS opens successfully, you are now mapping the WORK library to temp space on the server.

Invocation of SAS will not work if the Add Health share is not mapped.

Do not use this configuration of SAS for anything unrelated to the use of the Add Health restricted data. Use your regular installation of SAS.


Temp space allocation in Stata is controlled by setting an environment variable that points Stata to an alternate location on the file server.

Under Windows, a variation of the following four line batch file script will invoke Stata with appropriate temp file redirection. This example presumes mapping of Add Health data to the Z: drive.

set STATATMP=Z:\scratch
cd \work\bobj\pgms
start "" "C:\Program Files (x86)\Stata13\StataSE-64.exe"

The first statement sets the environment variable STATATMP to Z:\scratch.

The second statement changes the drive mapping to Z:.

The third statement sets the default directory to which Stata will point when launched. This is user-specific. You will need to provide a setting somewhere within your work directory.

The fourth line provides a batch file invocation of Stata13 that closes the CMD line window after loading the software. The specification shown should be appropriate for most users.

Save this file with a meaningful name and a batch file (.bat) extension. In this example, I saved it as:

C:\Users\bobj\My Documents\My Stata Files\Stata_AdHealth.bat

Browse to the location of this file. Right-click and copy. Paste a shortcut to the desktop. The title reads Stata_AdHealth - Shortcut, which I changed to Stata AdHealth.

Finally, right-click on the icon and select Properties. The Shortcut tab will be selected. Select the Change Icon... button and browse to the location of the Stata executables, where you can click on one to open an icon selection window that will allow you to apply a Stata icon like that shown in the figure below.


Test Stata invocation. Stata will load regardless of whether you have remembered to map the AdHealth data, so verify where you are in Stata by running a pwd (print working directory) command. If you get a result pointing to the local drive as below, you didn't map the drive or mapped it incorrectly.

. pwd
C:\Users\bobj\Documents\My Stata Files

The appropriate result for this example is:

. pwd