/* Program: example1_read_ASCII.sas */ /* SAS program to read ASCII data set, web_example1.asc, and */ /* demonstrate basic SAS reading, data selection, variable constr. */ /* and tabulating commands */ /* Author: D. Ribar Date: Sept. 1, 2008 */ /* Affix title to output */ TITLE1 "Example of how to read, process and tabulate PSID data"; /* Create internal file reference for ASCII file */ /* NOTE: THIS NEEDS TO BE CHANGED FOR PROGRAM TO WORK */ FILENAME example1 '[path]web_example1.asc'; /* Compress any SAS files that are produced by this program */ OPTIONS COMPRESS=YES; /* Data step to read and label raw data */ DATA t_ex1; /* Statements to read data from a space-delimited ASCII file */ INFILE example1; INPUT ER30001 ER30002 ER32000 ER33801 ER33802 ER33803 ER33804 ER33813 ER33817 ER33847 ER33848; /* Statements to attach labels to raw input variables; this can */ /* be done several ways: */ /* - individual LABEL statements: */ LABEL ER30001 = "1968 INTERVIEW NUMBER"; LABEL ER30002 = "PERSON NUMBER 68"; LABEL ER32000 = "SEX OF INDIVIDUAL"; /* - single LABEL statement with multiple arguments */ LABEL ER33801 = "2005 INTERVIEW NUMBER" ER33802 = "SEQUENCE NUMBER 05" ER33803 = "RELATION TO HEAD 05" ER33804 = "AGE OF INDIVIDUAL 05"; /* - ATTRIB(ution) statement -- these statements are useful when */ /* you need to assign several attributes to a variable */ ATTRIB ER33813 LABEL="EMPLOYMENT STATUS 05" ER33817 LABEL="YEARS COMPLETED EDUCATION 05" ER33847 LABEL="WHY NONRESPONSE 05" ER33848 LABEL="INDIVIDUAL WEIGHT NUMBER 1 05" FORMAT=7.3; /* Document the SAS data set, t_ex1, that was just created */ PROC CONTENTS; TITLE2 "All records, selected variables from 2005 individual file"; PROC MEANS; PROC FREQ; TABLE ER33847 ER33803*ER33813; /* Data step to read previous SAS data set, select respondents, and */ /* create several variables */ DATA t_ex1_rs; /* Use SET statement to read a SAS data set */ SET t_ex1; /* Use subsetting IF statement to select respondents */ IF ER33847 EQ 0; /* Respondents */ IF ER33813 GT 0 AND ER33813 LT 9; /* with valid employment info. */ IF ER33817 GT 0 AND ER33817 LT 98; /* with valid education info. */ /* Create employment indicator */ IF ER33813 EQ 1 THEN curr_emp = 1; ELSE curr_emp = 0; /* Create categorical education variable */ IF ER33817 LT 12 THEN cat_educ = "1 LT HS "; ELSE IF ER33817 LT 16 THEN cat_educ = "2 HS,