BookmarkSubscribeRSS Feed
ballardw
Super User

Try

DATA FOO;
  INFILE '/path/to/csv/file' DELIMITER = ',' MISSOVER DSD LRECL=32767 FIRSTOBS=2;
  INFORMAT ID 10.;
  INFORMAT BAR $64.;
  INPUT ID BAR $;
RUN;
Tom
Super User Tom
Super User

@tomcmacdonald wrote:

Here's what the CSV file looks like:

 

id,bar
1, 
2, 
3,Joe
4,Steve
5,Henry

So in that data the first two observations have empty values for BAR.

Is your problem that your dataset does NOT have empty value for BAR in those two cases or that you don't understand how SAS stores character variables?

 

Remember that SAS stores character variables as fixed length.  In your original data step one side effect of the INFORMAT statement you used is that BAR will be defined as a character variable of length 64.  So observations 1 and 2 should have BAR equal to 64 blanks. Observation 3 will have 'Joe' with 61 trailing blanks. In normal comparisons SAS will ignore the trailing blanks.  In PROC SQL SAS will treat a value that is all blanks as NULL.

 

But if you store it into an external DBMS as a CHAR(64) instead of a VARCHAR(64) variable then the external DBMS might not treat it as NULL.

 

If the issue is that the values are not empty then probably one of these two things happened.

 

If you read the data WITHOUT the TRUNCOVER option on the INFILE statement (or the deprecated MISSOVER option that your posted code is using) then the first two lines would be might have been read as one observation with ID=1 and BAR='2'.  Look for note to the effect that SAS went to a new line.

 

If your files has other non-printing characters then BAR will have something that looks blank but is not all blanks. Like a null character ('00'x) or a tab ('09'X) or a carriage return ('0D'x) or what microsoft calls a non-breaking space ('A0'x) or a DEL character ('7F'x). Or really anything with an ascii code less than a space ('20'x).

 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 16 replies
  • 2391 views
  • 0 likes
  • 5 in conversation