BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;
4 REPLIES 4
ger15xxhcker
Quartz | Level 8

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.

ballardw
Super User

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;
Tom
Super User Tom
Super User

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.   

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 360 views
  • 0 likes
  • 5 in conversation