How do I use a SAS setup file to import ASCII data?
Setup files contain the syntax or program code to read raw data (ASCII) into a statistical package. The instructions below demonstrate how to use SAS setup files in a Windows environment.
These instructions assume that you have already downloaded the ASCII data and SAS setup file from the Internet. If you have a compressed version of a file, you will have to decompress it before using the setup file.
Note: In order to successfully use setup files, you must know the exact location (i.e., full pathname, such as C:\My Documents\Data) and filename (e.g., da9999.txt) of the files that you obtained from ICPSR.
Download the SAS setup file from the ICPSR Web site.
Most of the files downloaded from the ICPSR Web site will be compressed. You will have to decompress the files using WinZip or other decompression software. More information about decompressing files can be found at the help page, How do I decompress the files I download from your site? Once the SAS setup file has been downloaded and decompressed, rename the file to add a '.sas' extension. This will allow SAS to recognize the file as a SAS syntax file.
Open SAS for Windows.
Open the SAS setup file in the SAS Program Editor window.
Click on File and then Open to get an Open File dialog box.
At the top of the box, where it says Look In, choose the path where the SAS setup file is located.
At the bottom of the box, set Files of Type to All Files.
You will then see a list of all files in the directory you selected. Either double-click on the SAS setup file or click once on the name of your chosen file (the name will appear after File Name) and then click on Open.
Since the SAS setup file is a text file, SAS will display the file in the SAS Program Editor.
Most ICPSR setup files contain a header that describes the contents of the file. Once you have opened the setup file in the SAS Program Editor, read the ICPSR header, if present, for important information about the file.
After reading the header, scroll to the DATA command. Add a dataset name for your data to this command line, if you want it located in the temporary SAS library 'work.' Please consult SAS documentation if you want the dataset saved in a permanent SAS library.
Scroll to the INFILE command. Replace the text that says physical-filename or file-specification with the full path and name of the data file you extracted from the downloaded file.
It is important that you include the full path (e.g., C:\My Documents\Data); otherwise SAS may not be able to locate the file. For example, if you downloaded the data for ICPSR 2992 into the directory C:\My Documents\Data and you called the file da2992.txt, then the INFILE command should read:
INFILE 'C:\My Documents\Data\da2992.txt' LRECL=30;
(Note that the LRECL varies by study and the correct number will already be provided in the SAS setup file.)
If there are PROC FORMAT, FORMAT, or MISSING VALUE RECODE commands in the setup file, ICPSR usually places SAS comment delimiters before (/*) and after (*/) the appropriate section, which means that SAS will not automatically read these commands. If you want SAS to read and execute these commands, you should remove the set of comment markers for each section.
Scroll to the end of the setup file. If a RUN command is not already there, then type one in. Make sure the command ends with a semicolon.
You are now finished editing the SAS setup file. Run the statements by clicking on Run > Submit.
The log file will show the commands that SAS processed, as well as any error messages.
The data can now be used for analysis. If you are using SAS System for Windows Release 7.0 or higher, you can view the data file in the SAS Table Editor. Go to the Tools menu bar and select Table Editor. Once the Table Editor window appears, click on File and Open to open your newly-created data file. The data file will be located in the Work library unless you changed the library reference prior to running the setup file. Click on the data file and then on Open to see the data displayed in the Table Editor.
Users should be aware that a SAS dataset created in the Work library will be discarded at the end of the SAS session. To save a SAS dataset for subsequent SAS sessions you must assign the file a two-level name. The first level is the library name and the second level is the dataset name. This can be done in Windows by selecting Save As... under the File menu in the VIEWTABLE window, creating a new library using the Create New Library icon, then specifying a data table name and clicking on Save. Please refer to your SAS manual or SAS System Help for more information about saving SAS data sets.
For further help with the SAS System for Windows, consult the HELP menu on the top toolbar of SAS or refer to your SAS manual.
This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.