Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.

Similar presentations


Presentation on theme: "1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009."— Presentation transcript:

1 1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009

2 2 Outline Fixing programs that don’t work Data step debugger SAS truncates a character variable SAS stops in the middle of the job SAS runs out of memory or Disk Space

3 3 1. Fixing programs that don’t work Read the SAS log SAS log has three types of messages about your program: errors, warnings, and notes. Start at the beginning when you read SAS log. Look for common mistakes first. Check your syntax. Searching for missing semicolon Most common errors in SAS. SAS usually give nonsense message when you miss semicolon. Use DATASTMTCHK system option EX: Options DATASTMTCHK=ALLKEYWORDS;

4 4 Note: Input statement reached past the end of the line If you see the note ‘SAS went to a new line when Input statement reached past the end of the line’, it usually means there is a problem. It means SAS was reading your data, it got to the end of the data line before it read values for all the variables in your Input statement. Possible causes: blank lines in your data file, use list input without a space between every value, some data lines are shorter than the rest and you are using column or formatted input. Use Proc Print or Viewtable to check your SAS data set.

5 5 Note: Lost Card A lost card means that SAS are expecting another line of data and did not find it. Printing the SAS data set as well as careful proofreading of the data file can be helpful in identifying problem areas.

6 6 Note: Invalid Data Common reasons for invalid data: Character values in a field that should be numeric Forgetting to specify that a variable is character Incorrect column specifications producing embedded spaces in numeric data List-style input with two periods in a row and no space in between Missing data not marked with a period for list-style input causing SAS to read the next data value. Special characters such as tab in numeric data Using the wrong informat such as MMDDYY instead of DDMMYY. Invalid dates (Sep. 31) read with a date informat.

7 7 Note: Numeric values have been converted to character When you accidentally mix numeric and character variables, SAS tries to fix your program by converting variables from numeric to character or vice versa. Converting variables Character to Numeric Newvar=Input (oldvar, informat); EX: newscore2=input(score2, 2.); Numeric to Character Newvar=PUT(oldvar, format); NewID=PUT(studentID, 3.);

8 8 Data step produces wrong results but no error message Use the Put and Putlog statements to debug. Put and Putlog statement: Putlog _ALL_; or Putlog variable-1= variable-2= … variable-n=; Ex: Data lowscore; infile ‘c:\class.dat’; Input name $ score1 score2 score3 Homework; Homework=Homework*2; averagescore=mean(score1+score2+score3+Homework); Putlog name= score1= score2= score3= Homework= averagescore=; If averagescore < 70; Run;

9 9 2. Data step debugger Starting the debugger (class.dat data set) Data lowscore/debug; infile ‘c:\class.dat’; Input name $ score1 score2 score3 Homework; Homework=Homework*2; averagescore=mean(score1+score2+score3+Homework); Putlog name= score1= score2= score3= Homework= averagescore=; If averagescore < 70; Run;

10 10 Data step debugger (cont’d) Executing debugger commands Command Results Execute one statement Step n Execute n statements Examine variable-list Prints the values of variables Set variable=expression Assigns a value to a specified variable for the current observation Go Finishes executing the Data Step Quit closes the debugger Ex: Examine _All_

11 11 Possible causes for invalid options and statements A misspelled key words A missing semicolon A Data step statement in a Proc step (or vice versa) A Run statement in the middle of a DATA or Proc Step The correct option with the wrong statement An unmatched quotation mark An unmatched comment.

12 12 Possible causes for “Variable not found” Misspelling a variable name Using a variable that was dropped at some earlier time Using the wrong data set Committing a logic error, such as using a variable before it is created.

13 13 3. SAS truncates a character variable The length of character variables are determined by the following methods: Input statement Ex: Input Food $; length: 8 Input Food $1-10; length: 10 Input Food $15.; length: 15 Assignment statement Ex: data summer; set temps; If Temperature > 100 then Status=‘Hot’; else Status=‘Cold’;

14 14 SAS truncates a character variable (cont’d) Length statement in Data step Ex: Length Status $4 Food $15; Attrib statement in Data step Ex: Attrib Status Length=$4 Label=‘Hot or Cold’; Data carsurvey; infile 'D:\Cars.dat'; input age sex income color$; length agegroup $6; if age < 20 then agegroup='Teen'; else if age < 65 then agegroup='Adult'; else agegroup='Senior'; proc print data=carsurvey; title 'Car color survey results'; run;

15 15 4. SAS stops in the middle of a job Possible causes: An unmatched quotation mark Submit ‘; run; An unmatched comment Submit */; run; No Run statement at the end of a program Submit run; Not sure what the problem is? Submit *’; *”; */; run; Out of time Batch system may have time limit, talk to systems programmer or other SAS user at your site. /* in the first column

16 16 5. SAS runs out of memory or disk space Memory and disk space Decrease the number of bytes needed to store the data to help decrease disk storage. Default is eight bytes for both numeric and character variables, can decrease it using input, length or attrib statement EX: length Answer $1; length Tigers 4; Subset your data or decrease the number of variables Clear the SAS log and output often. Compress SAS data set (might increase the size of your data set sometime) Ex: Data comzoo (Compress=YES); set zoo;


Download ppt "1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009."

Similar presentations


Ads by Google