*Copyright @ www.mycsg.in;
Why log review matters in SAS
The SAS log reports errors warnings and important notes produced during execution
Many programs appear to run successfully while still producing incorrect results because of overlooked log messages
This lesson shows common log issues and the coding situations that create them
Variable is uninitialised
Create input data
data input; infile cards truncover; input studyid $ subject $ age dob : date9.; format dob date9.; cards; MYCSG 1001 72 1jan1947 MYCSG 1002 69 2jan1950 MYCSG 1003 . . MYCSG 1004 40 1apr1983 ; run;
Copy Code
View Log
SAS Log
data input; infile cards truncover; input studyid $ subject $ age dob : date9.; format dob date9.; cards; NOTE: The data set WORK.INPUT has 4 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds ; run;
Name a variable on LENGTH but never assign a value to it
Declaring a variable does not automatically create values for it on output rows
If the variable is never assigned SAS can note that it is uninitialised
data output; set input; length usubjid $10; run;
Copy Code
View Log
SAS Log
data output; set input; length usubjid $10; run; NOTE: Variable USUBJID is uninitialized. NOTE: There were 4 observations read from the data set WORK.INPUT. NOTE: The data set WORK.OUTPUT has 4 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
View Data
Dataset View
Type the wrong variable name in an expression
Spelling mistakes in variable names are a common source of uninitialised variable messages
data output; set input; if age ne . then agemon=aeg*12; run;
Copy Code
View Log
SAS Log
data output; set input; if age ne . then agemon=aeg*12; run; NOTE: Variable AEG is uninitialized. NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 3 at 1397155:32 NOTE: There were 4 observations read from the data set WORK.INPUT. NOTE: The data set WORK.OUTPUT has 4 observations and 6 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
View Data
Dataset View
Specify a variable on RETAIN but do not create it meaningfully
A retained variable still needs logic that gives it useful values
data output; set input; retain subjcount; run;
Copy Code
View Log
SAS Log
data output; set input; retain subjcount; run; NOTE: Variable SUBJCOUNT is uninitialized. NOTE: There were 4 observations read from the data set WORK.INPUT. NOTE: The data set WORK.OUTPUT has 4 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
View Data
Dataset View
Missing values were generated as a result of performing an operation on missing values
Perform arithmetic on a variable that contains missing values
data output; set input; agemon=age*12; run;
Copy Code
View Log
SAS Log
data output; set input; agemon=age*12; run; NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1412133:15 NOTE: There were 4 observations read from the data set WORK.INPUT. NOTE: The data set WORK.OUTPUT has 4 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
View Data
Dataset View
Use a non-existing variable in an expression
data output; set input; agemon=aeg*12; * correct expression - agemon=age*12; run;
Copy Code
View Log
SAS Log
data output; set input; agemon=aeg*12; * correct expression - agemon=age*12; run; NOTE: Variable AEG is uninitialized. NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 4 at 1419618:15 NOTE: There were 4 observations read from the data set WORK.INPUT. NOTE: The data set WORK.OUTPUT has 4 observations and 6 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
View Data
Dataset View
Apply functions to values that may be missing
data output; set input; month=month(dob); year=year(dob); run;
Copy Code
View Log
SAS Log
data output; set input; month=month(dob); year=year(dob); run; NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1427103:11 1 at 1427104:10 NOTE: There were 4 observations read from the data set WORK.INPUT. NOTE: The data set WORK.OUTPUT has 4 observations and 6 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
View Data
Dataset View
Round a variable that is missing on some rows
data bmi; infile cards truncover; input usubjid bmi; cards; 1001 23.6789 1002 . 1003 35.1983 ; run; data output; set bmi; aval=round(bmi,0.01); run;
Copy Code
View Log
SAS Log
data bmi; infile cards truncover; input usubjid bmi; cards; NOTE: The data set WORK.BMI has 3 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds ; run; data output; set bmi; aval=round(bmi,0.01); run; NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1434599:10 NOTE: There were 3 observations read from the data set WORK.BMI. NOTE: The data set WORK.OUTPUT has 3 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
View Data
Dataset View
All variables passed to some numeric functions are missing
This example helps compare how functions behave when some or all values are missing
data scores; infile cards truncover; input usubjid $ visit $ score1 score2 score3; cards; 1001 Week1 10 20 30 1001 Week2 9 20 29 1001 Week3 . . 25 1001 Week4 . . . 1001 Week5 10 15 . 1001 Week6 10 20 30 ; run; data output; set scores; nresp=n(score1,score2,score3); missresp=nmiss(score1,score2,score3); sumscore=sum(score1,score2,score3); avgscore=mean(score1,score2,score3); run;
Copy Code
View Log
SAS Log
data scores; infile cards truncover; input usubjid $ visit $ score1 score2 score3; cards; NOTE: The data set WORK.SCORES has 6 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds ; run; data output; set scores; nresp=n(score1,score2,score3); missresp=nmiss(score1,score2,score3); sumscore=sum(score1,score2,score3); avgscore=mean(score1,score2,score3); run; NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1442103:14 1 at 1442104:14 NOTE: There were 6 observations read from the data set WORK.SCORES. NOTE: The data set WORK.OUTPUT has 6 observations and 9 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
View Data
Dataset View
Character values were converted to numeric values
Create input data
data age; infile cards truncover; input subject $ age $; cards; 1001 72 1002 69 1003 45 1004 ; run;
Copy Code
View Log
SAS Log
data age; infile cards truncover; input subject $ age $; cards; NOTE: The data set WORK.AGE has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds ; run;
Use a character variable where SAS expects a numeric expression
proc contents data=age out=cont01; run; data output; set age; agemon=age*12; run;
Copy Code
View Log
SAS Log
proc contents data=age out=cont01; run; NOTE: The data set WORK.CONT01 has 2 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.00 seconds cpu time 0.00 seconds data output; set age; agemon=age*12; run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 1449612:12 NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1449612:15 NOTE: There were 4 observations read from the data set WORK.AGE. NOTE: The data set WORK.OUTPUT has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
View Data
Dataset View
Numeric values were converted to character values
Create input data
data age1; infile cards truncover; input subject $ age; cards; 1001 72 1002 69 1003 45 1004 . ; run;
Copy Code
View Log
SAS Log
data age1; infile cards truncover; input subject $ age; cards; NOTE: The data set WORK.AGE1 has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds ; run;
Use a numeric variable where SAS expects character processing
proc contents data=age1 out=cont01; run; data output; set age1; agec=strip(age)||" Years"; run;
Copy Code
View Log
SAS Log
proc contents data=age1 out=cont01; run; NOTE: The data set WORK.CONT01 has 2 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.01 seconds data output; set age1; agec=strip(age)||" Years"; run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 1457120:16 NOTE: There were 4 observations read from the data set WORK.AGE1. NOTE: The data set WORK.OUTPUT has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
View Data
Dataset View
Variable in DROP KEEP or RENAME list has never been referenced
Warning example in a KEEP statement
data class; set sashelp.class; run; data class2; set class; keep nmae age sex; run;
Copy Code
View Log
SAS Log
data class; set sashelp.class; run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds data class2; set class; keep nmae age sex; run; WARNING: The variable NMAE in the DROP, KEEP, or RENAME list has never been referenced. NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.CLASS2 has 19 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
View Data
Dataset View
Error example in a dataset option KEEP list
data class2; set class(keep=nmae sex age); run;
Copy Code
View Log
SAS Log
data class2; set class(keep=nmae sex age); ERROR: The variable NMAE in the DROP, KEEP, or RENAME list has never been referenced. run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.CLASS2 may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.CLASS2 was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Division by zero detected
Create input data
data scoring; infile cards truncover; input usubjid $ paramcd $ aval base; cards; 1001 SMWT01 100 90 1002 SMWT01 49 50 1003 SMWT01 68 0 ; run;
Copy Code
View Log
SAS Log
data scoring; infile cards truncover; input usubjid $ paramcd $ aval base; cards; NOTE: The data set WORK.SCORING has 3 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds ; run;
Percent change calculation with a denominator of zero
data scoring2; set scoring; pchg=(aval-base)/base*100; run;
Copy Code
View Log
SAS Log
data scoring2; set scoring; pchg=(aval-base)/base*100; run; NOTE: Division by zero detected at line 1472128 column 21. USUBJID=1003 PARAMCD=SMWT01 AVAL=68 BASE=0 PCHG=. _ERROR_=1 _N_=3 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1472128:21 NOTE: There were 3 observations read from the data set WORK.SCORING. NOTE: The data set WORK.SCORING2 has 3 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
View Data
Dataset View
Invalid argument to function INPUT
Create input data
data age1; infile cards truncover; input subject $ agec $; cards; 1001 72 1002 69 1003 45 1004 NA ; run;
Copy Code
View Log
SAS Log
data age1; infile cards truncover; input subject $ agec $; cards; NOTE: The data set WORK.AGE1 has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds ; run;
Convert text to numeric when some values are not valid numbers
data age2; set age1; age=input(agec,best.); run;
Copy Code
View Log
SAS Log
data age2; set age1; age=input(agec,best.); run; NOTE: Invalid argument to function INPUT at line 1479633 column 9. SUBJECT=1004 AGEC=NA AGE=. _ERROR_=1 _N_=4 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 1479633:9 NOTE: There were 4 observations read from the data set WORK.AGE1. NOTE: The data set WORK.AGE2 has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
View Data
Dataset View
File DATA does not exist
Refer to a non-existing dataset on SET
data class; set sashelp.calss; * correct - sashelp.class; run;
Copy Code
View Log
SAS Log
data class; set sashelp.calss; * correct - sashelp.class; ERROR: File SASHELP.CALSS.DATA does not exist. run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.CLASS may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.CLASS was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Refer to a non-existing dataset in a procedure
proc print data=sashelp.calss; run;
Copy Code
View Log
SAS Log
proc print data=sashelp.calss; ERROR: File SASHELP.CALSS.DATA does not exist. run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE PRINT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
BY variables are not properly sorted on data set
BY processing requires the dataset to be sorted by the same BY variables first
data class; set sashelp.class; run; data class01; set class; by sex; run;
Copy Code
View Log
SAS Log
data class; set sashelp.class; run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds data class01; set class; by sex; run; ERROR: BY variables are not properly sorted on data set WORK.CLASS. NAME=Alfred SEX=M AGE=14 HEIGHT=69 WEIGHT=112.5 FIRST.SEX=1 LAST.SEX=1 _ERROR_=1 _N_=1 NOTE: The SAS System stopped processing this step because of errors. NOTE: There were 2 observations read from the data set WORK.CLASS. WARNING: The data set WORK.CLASS01 may be incomplete. When this step was stopped there were 0 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
MERGE statement has more than one data set with repeats of BY values
This message usually indicates a many to many merge situation
Such merges need extra care because the resulting row structure may not be what the programmer intended
data height; infile cards truncover; input subject $ visitnum height; cards; 1001 1 170 1001 2 171 1002 1 165 ; run; data weight; infile cards truncover; input subject $ visitnum weight; cards; 1001 1 70 1001 2 71 1001 3 72 1002 1 68 ; run; proc sort data=height; by subject; run; proc sort data=weight; by subject; run; data merged; merge height weight; by subject; run;
Copy Code
View Log
SAS Log
data height; infile cards truncover; input subject $ visitnum height; cards; NOTE: The data set WORK.HEIGHT has 3 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds ; run; data weight; infile cards truncover; input subject $ visitnum weight; cards; NOTE: The data set WORK.WEIGHT has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds ; run; proc sort data=height; by subject; run; NOTE: There were 3 observations read from the data set WORK.HEIGHT. NOTE: The data set WORK.HEIGHT has 3 observations and 3 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.01 seconds cpu time 0.00 seconds proc sort data=weight; by subject; run; NOTE: There were 4 observations read from the data set WORK.WEIGHT. NOTE: The data set WORK.WEIGHT has 4 observations and 3 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds data merged; merge height weight; by subject; run; NOTE: MERGE statement has more than one data set with repeats of BY values. NOTE: There were 3 observations read from the data set WORK.HEIGHT. NOTE: There were 4 observations read from the data set WORK.WEIGHT. NOTE: The data set WORK.MERGED has 4 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
View Data
Dataset View
Key points to remember
The SAS log is a primary validation tool, not just a place to look when code fails completely
Warnings and notes about type conversion, missing values, sorting, and uninitialised variables can all signal real data problems
Review the code and the resulting datasets together when investigating a log issue