The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use (other programs) » SAS formatting programs
Re: SAS formatting programs [message #11103 is a reply to message #11099] Thu, 27 October 2016 05:51 Go to previous messageGo to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 2536
Registered: February 2013
Senior Member
If you downloaded the flat file, it comes with .SAS and .DAT files. The .SAS file is the SAS program to be executed in order to read the ASCII dataset and create a SAS dataset, and the .DAT file is the ASCII file used in the .SAS file. The modification of the .SAS file depends on whether a temporary or permanent SAS data set is needed. In either case, the .DAT file does not need any modification.
CREATING A PERMANENT SAS DATA SET 1.

In the LIBNAME statement (line 1 of the .SAS file), specify the path of the directory where the permanent SAS data set will be stored.

Example: LIBNAME user 'C:\COUNTRY'; To call up the format associated with the variables in the SAS data file, add the following statement in a blank line following line

1: OPTIONS FMTSEARCH=(user);

2. Create a permanent format catalog by adding the name of the library reference used in the LIBNAME statement, to the PROC FORMAT statement (in line 3) as follows: PROC FORMAT LIB = user;

In this example, a permanent format catalog will be stored in the directory called 'C:\COUNTRY'.

3. On the DATA statement line, precede the name of the data file being created with a period and the library reference name specified in the LIBNAME statement. The LIBNAME, period and data file name should form one word. DATA user.datasetname;

4. In the INFILE statement, add the path for the directory in which the .DAT file is located. INFILE 'C:\COUNTRY\datasetname.dat';

5. Add a RUN statement at the end of the .SAS file if there is no other SAS statement following the DATA step. RUN; A permanent SAS data file will be created in the specified directory, which will also contain the format catalog. The formats associated with the variables in the SAS data file are recalled in a new SAS session by adding the following statement to the SAS program: OPTIONS FMTSEARCH = (user); where user is the library reference name given in the LIBNAME statement. This statement should appear before the SAS data file is used in a DATA step or PROC statement.

CREATING A TEMPORARY SAS DATA SET

1. Delete the LIBNAME statement.

2. In the INFILE statement, add the path for the directory in which the .DAT file is located.

3. Add a RUN statement at the end of the .SAS file if there is no other SAS statement following the DATA step.

NOTE: The DATA statement (Data datasetname;) must always be on the line immediately before the very first ATTRIB statement. If the statement is at a different location, please MOVE it. Also, the default value for maximum record length is 256, but if the longest record in the dataset is greater than 256, you need to edit the INFILE statement. Please include the parameters INFILE {datasetname} LRECL={maximum record length} MISSOVER. INFILE 'C:\COUNTRY\datasetname.dat' LRECL=max.rec.length# MISSOVER;

Please let us know if this answers your question.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Reading in Niger HH data into SAS Enterprise Guide
Next Topic: Opening databases in RStudio
Goto Forum:
  


Current Time: Thu May 19 06:55:55 Coordinated Universal Time 2022