Hello
The last row has missing value in variable Var2 (char).
Why can't I see this row in the data set?
data t;
infile cards dlm=' ' dsd truncover;
Input var1 var2 $ var3;
cards;
1 a 10
1 a .
1 b .
2 b 20
2 b 30
2 b 40
3 a 50
3 b .
3 a 60
3 b 70
3 a 80
3 a 90
3 a 100
. a 110
. 120
;
Run;
You have three delimiters in the last row, causing all variables to be read as missing.
The row containing the missing values was not included in the data set because the TRUNCOVER option was specified in the INFILE statement. When TRUNCOVER is used, SAS will ignore incomplete observations that are missing one or more variable values. In this case, the row with the missing value (Var2) is ignored by SAS.
Appears to possibly be a SAS version difference. I "see" a data row, but it has 3 missing values because of the interaction of DSD and your space delimiter.
If you have space as a delimiter then you really do want to make sure that you use . in data lines to indicate missing values. Such as this with the Var2 value as . Note that . alone are not read as character values but as missing.
data t; infile cards dlm=' ' dsd truncover; Input var1 var2 $ var3; cards; 1 a 10 1 a . 1 b . 2 b 20 2 b 30 2 b 40 3 a 50 3 b . 3 a 60 3 b 70 3 a 80 3 a 90 3 a 100 . a 110 . . 120 ; Run;
Or use a different delimiter such as:
data t; infile cards dlm=',' dsd truncover; Input var1 var2 $ var3; cards; 1,a,10 1,a,. 1,b,. 2,b,20 2,b,30 2,b,40 3,a,50 3,b,. 3,a,60 3,b,70 3,a,80 3,a,90 3,a,100 .,a,110 ., ,120 ; Run;
If you change the spaces to a visible character is becomes more obvious.
infile cards dlm=',' dsd truncover;
input var1 var2 $ var3;
cards;
.,,,120
;
Since you told it to use DSD option the last line has 4 values on it instead of the 3 the INPUT statement is expecting.
If you want to use a value that has the delimiter in it then the value must be quoted. So using the version with commas so it is easier to see that means:
infile cards dlm=',' dsd truncover;
input var1 var2 $ var3;
cards;
.,",",120
;
Now there are three values. The second one consisting only of one copy of the delimiter character.
The easier solution is to use . in the data files to represent missing for both numeric and character values. The normal informat will interpret a single period as missing. If you want to actually read that as a character string '.' you need to use the $CHAR informat instead. And since your delimiter is a space there is generally no need for DSD option.
data t;
infile cards truncover;
input var1 var2 $ var3;
cards;
1 a 10
1 a .
1 b .
2 b 20
2 b 30
2 b 40
3 a 50
3 b .
3 a 60
3 b 70
3 a 80
3 a 90
3 a 100
. a 110
. . 120
;
Normally you don't want to use DSD when space is the delimiter. Humans use spaces to make the columns look neater.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: