Cornell University Cornell University CISER

CISER Computing

SAS Sample Programs

The following SAS programs were written or modified by CISER staff. Many of them are based on examples provided in "SAS Language and Procedures: Introduction (Version 6)" and "SAS Language and Procedures:
Usage (Version 6)".

When working with these programs, please remember to substitute
appropriate path names. The data is stored on the CISER research servers in the V:\ drive.

ADDVAR.SAS
Reads a SAS data set and creates new modified data sets. Creates new variables and modifies existing variables. Uses the length statement for character variables. Deletes observations.

AG_CEN.SAS
Pulls data for the years 1982, 1987, and 1992 from the 1992 Census of Agriculture for NY State. Reads the data file "cag92.usco" saved in
folder "V:\cag\009\". Uses PROC TRANSPOSE in a macro to create a transposed dataset for individual years.

ARITH_FC.SAS
Reads a SAS data set and creates new data sets. Uses arithmetic operators and SAS functions

ASCII.SAS
Creates a fixed column ASCII data file from the SAS dataset.

CAT_MERG.SAS
Uses PROC COPY to copy catalogs from one directory to another. Uses PROC BUILD to merge catalogs.

CEN90EX.SAS
To create a flat ascii file with a fixed logical record length from selected data in the Census of Population and Housing, 1990. Reads the data file "da6150" saved in folder "V:\cen1990/008B.0001\". Uses RETAIN statement to combine household level information with person level information.

CHAR2NUM.SAS
Example of changing a character variable into a numeric variable.

CHAR-VAR.SAS
Works with character variables. Deals with MIXED case character values. Uses the LENGTH statement when creating new character variables. Aligns values in character variables. Handles missing values when creating new character variables.

CHECKTRN.SAS
Checks contents of a SAS transport file.

CHKDAT.SAS
Prints out a few records from external (raw) data file. Uses an arbitrary LRECL to determine actual LRECL. Prints output to the log

CIMPORT.SAS
Uses PROC CIMPORT to read a SAS transport file created by using PROC CPORT.

COMB_REC.SAS
Combines information from several consecutive records in input raw data to create a single observation in output SAS dataset.

COMPROCS.SAS
Compares PROC MEANS with PROC SUMMARY.

COMPUST.LST
Output from COMPUST.SAS.

COMPUST.SAS
Working with COMPUSTAT sas datasets. Program to obtain an extract from COMPUSTAT dataset.

CONCATEN.SAS
Uses a macro to concatenate a number of SAS datasets.

COSTAT.SAS
Program reads a raw data file for USA Counties and creates a SAS data set with a few selected variables.

CPORT.SAS
Uses PROC CPORT to create a transport file from SAS datasets.

CRSP.SAS
Working with CRSP sas datasets. Program for pulling data for a single CRSP firm for a specified period of time.

CRSPCON.SAS
Working with CRSP sas datasets. Program to list the contents of all the datasets in the /crsp/dx library.

DATADUMP.SAS
Program prints a few records from a raw data file into SAS log.

DATASET.SAS
Reads an external data file. Uses column input. Creates a permanent SAS data set. Uses FILENAME, INFILE, and LIBNAME statements. Checks the CONTENTS of the SAS data set.

DATES.SAS
Creates a data set that includes dates. Uses a FORMAT Statement in PROC Step and DATA Step. Sorts Dates. Creates new DATE variables. Uses DATES as constants. Using SAS Date Functions. Calculates a duration in days and in years.

DBF2SAS.SAS
Program to create a SAS data file from a dBase III data file.

DECIMAL.SAS
Reads data with implied decimals. Uses COLUMN POINTER and simple INFORMAT.

DELTEMP.SAS
Sample program to delete data sets from the SAS work space.

DIF2SAS.SAS
Program to convert a DIF file into a SAS dataset.

DO_ARRAY.SAS
Uses DO group in IF/THEN Statement. Uses ARRAYS and iterative DO loops.

DUPL_OBS.SAS
Removes the DUPLICATE observations from SAS data set with PROC SORT

EDIT_DAT.SAS
Reads a SAS data set and creates new modified SAS data sets. Creates new variables and modifies existing variables. Uses the length statement for character variables. Deletes observations.

ENTER.SAS
Enters own data. Uses list input format

FILEPUT.SAS
Sample program to create an ascii file from a SAS data set.

FIRS_LAS.SAS
Finds the FIRST and the LAST observation in a grouped data set

FORM_INP.SAS
Creates a SAS Data Set using Formatted Input.

GCHART.SAS
SAS/GRAPH: Creating Pie Chart with SAS.

GET_TS2.SAS
Analysing CRSP Data. Program to obtain the pre and post 30 days of return from daily time series data, as in CRSP data.

GR_MAP.SAS
SAS/GRAPH: Creating Surface and Block Maps.

IF_OUTPU.SAS
Deletes observation based on a condition. Uses the implicit action of subsetting IF. Compares the DELETE and Subsetting IF Statement. Writes observations to Multiple SAS Data Sets with OUTPUT statement. Combines Assignment and OUTPUT Statements. Assignes observations to more than one Data Set.

IF_THEN.SAS
Uses IF/THEN/ELSE Statements. Uses Comparison Operators. Writes mutually exclusive conditions. Uses the Logical Operators "AND" and "OR". Uses Numeric comparisons. Deals with MIXED case character values.

IML_EX.SAS
Example of creating a PROC IML module. Creates a submatrix. Generates a matrix of random normal numbers. Uses a MACRO to run the module several times.

IMPORT.SAS
Uses PROC COPY to read SAS transport file (XPORT file).

INCLUDE.SAS
Example of using %INLUDE statement to bring SAS programming statements  saved in a text file into a current SAS program.

LINKREC1.SAS LINKREC2.SAS
Reads data with multiple record types. Links data from two record types to create a single observation. Uses data from The Census of Population and Housing, 1990, Public Use Microdata Sample: 1/1000.

LISTMOD.SAS
Example of a modified list input.

MACR_EX1.SAS
Example of creating a MACRO. Uses a MACRO to run a PROC IML module several times.

MACR_EX2.SAS
Uses a MACRO to work with two SAS datasets. Macro takes one observation at a time from the first dataset. Uses the obs to create new variables with the second dataset,and creates new SAS dataset each time

MACR_EX3.SAS
Uses a MACRO to create a number of datasets from a SAS dataset. Does Regressions with the new datasets and saves regression coefficients in SAS datasets.

MATMERG.SAS
Match-Merges SAS data sets.

MED_MACR.SAS
Uses a macro to work with two SAS datasets. Macro takes one observation at a time from the first dataset. Uses the obs to create new variables with the second dataset,and creates new SAS dataset each time

MIXFMT.SAS
Uses Mixed Input Formats. Reads and writes Dates.

MODIFY.SAS
Reads a SAS data set and creates new modified SAS data sets. Creates new variables and modifies existing variables. Uses the length statement for character variables. Deletes observations.

MULTIDAT.SAS
Reads a SAS data set and creates multiple SAS data sets in one data step. 

MULTFILE.SAS
An example of reading multiple text files in a single data step to create a SAS data set. 

MULTIVAR.SAS
Reads in multiple variables. Uses COLUMN POINTER and simple INFORMAT.

OPTIONS.SAS
Changes system OPTIONS. Checks System Defaults. Alters PAGESIZE and CENTERs output. NUMBERs Pages and prints DATE and time. Customizes output of MISSING values.

OSIRIS.SAS
Accessing an OSIRIS file.

OUTPUT.SAS
Creates new data set with the OUTPUT from a SAS procedure. Uses PROC MEANS and PROC SUMMARY to output a data set. Uses CLASS, SORT and BY statements.

PMEANS.SAS
Uses PROC MEANS with selected VARiables and keywords. Uses BY Statement and CLASS Statement.

PROCFREQ.SAS
Produces FREQuency Tables. Produces Crosstabulations. Produces N-Way Tables. Selects observations with PROC FREQ.

PUMS1.SAS PUMS2.SAS
Reads data with multiple record types. Links data from two record types to create a single observation. Uses data from The Census of Population and Housing, 1990, Public Use Microdata Sample: 1/1000.

RAND_SAM.SAS
Generates a random sample of observations from a SAS dataset.

READCOL.SAS
Reads an external file. Uses column input format.

READEX.SAS
Reads an external file. Uses list input format.

READLIM.SAS
Examples of reading delimited raw data files.

READTRN.SAS
Uses PROC COPY to read SAS transport file (XPORT file).

SAS2DBF.SAS
Uses PROC CONVERT to create a dbaseIII file from a SAS dataset.

SAS2DIF.SAS
Uses PROC CONVERT to create a DIF file from a SAS dataset.

SASPROCS.SAS
Uses SAS procedures. Processes selected variables and observations based on a condition. Processes data in groups.

SD2TOSSD.SAS
Converts datasets created by Windows/SAS version 6 to version 9. Uses DATECOPY to preserve the original file creation dates. Renames data files using PROC DATASETS.

SELE_CON.SAS
Uses a macro to create a number of datasets from a SAS dataset. Does Regressions with the new datasets and saves regression coefficients in SAS datasets.

SELECOBS.SAS
Reads a SAS data set. Creates SAS data sets with selected observations.

SELECT.SAS
Uses the line pointer and multiple input statements to select observations based on the values of particular variables.

SELECVAR.SAS
Reads SAS data set and creates new SAS data sets that contain selected variables.

SIND_DAT.SAS
Data Extraction from World Tables of Economic and Social Indicators 1950-1992.

SORTDATA.SAS
Sorts a grouped data set. Arranges Groups in DESCENDING order. Finds the FIRST and LAST observation in each group.

SPSS.SAS
Sample programs to access SPSS files.

SUMBYOBS.SAS
An example of using PROC MEANS with BY and OUTPUT statements to produce a summary data set.

SUMFIPS.SAS
A sample program to sum across observations, as in FIPS codes. Program sums across observations and creates a new record based on the sums. The new record is then integrated into the original data file, replacing the individual records from which is is created.

TITLES.SAS
TITLES, FOOTNOTES, LABELS, AND FORMATS

TOTALDAT.SAS
Accumulates a total for an entire data set. Accumulates a total for each BY Group.

TRANSPOS.SAS
Program uses PROC TRANSPOSE to transpose a SAS dataset.

TRANSPRT.SAS
Creates a SAS transport file (XPORT file) from SAS datasets.

UPDATE.SAS
Uses PROC COPY with DATECOPY option to create SAS 7/8 data files from SAS 6 data files.

USA_CNTY.SAS
Program reads a raw data file for USA Counties and creates a SAS data set with a few selected variables. Converts a SAS data set into a SAS transport file.

USE_DLM.SAS
Example of using DLM option to create a SAS data set from a delimited raw data file.

USELRECL.SAS
Reads an external file with a "long" logical record length. Reads selected observations.

WHERE.SAS
Uses the WHERE Data Set option. Uses the WHERE Statement.