Help using Base SAS procedures

Reading in a .csv file: a period added to a variable?

Reply
New Contributor
Posts: 2

Reading in a .csv file: a period added to a variable?

Dear All,

I'm trying to reading in a .csv file, but getting an error message on reading in one variable.  The variable is a person's ID number.  When I read in the file using an infile statement, I see a note saying that "Invalid data for this variable." In the log, I see a period added to this variable, which does not exist in the original .csv file.  For instance, I see "84031563578"  in the .csv file, but I see ".84031563578" in the SAS log instead.  I don't know where this period came from.  Can anyone suggest how I can fix this problem?  Thank you!!!

SJK

Valued Guide
Posts: 632

Re: Reading in a .csv file: a period added to a variable?

This could be an informat issue.  Take a look at your INFORMAT for that field.  Can we see your INPUT statement?

Regular Contributor
Posts: 198

Re: Reading in a .csv file: a period added to a variable?

"Id.Number" indicates that the column contains only digits.

This is a far-out suggestion:

Compare your id to

%Put SysMaxLong:&SysMaxLong;

Perhaps your id.numbers are greater than SAS can represent

which causes it to place the 'number' in a decimal format such as you are seeing.

Appropriately it ought to have a leading zero: 0.84031563578

next: 64-bit SAS

Ron Fehd  id maven

New Contributor
Posts: 2

Re: Reading in a .csv file: a period added to a variable?

Thank you all!  I fixed an informat statement, and now it works!  I also assigned a proper number of places for the variable.

But I got a new problem.  I have a series of data sets - 11 data sets that represent a data set from each month from Feb 2012 to Dec 2012.

I tried to read in all files at once by using the FILENAME statement, for example,

*FILENAME indat (

  'C:\Users\sjk845\Desktop\data\feb2012.csv'

   ...

   ...

  'C:\Users\sjk845\Desktop\data\dec2012.csv'

);

and refer indat in my INFILE statement.

DATA all;

   INFILE indat DSD TRUNCOVER FIRSTOBS=2 TERMSTR=CR;

............

The problem is that it treats the header from files other than the first referred file (i.e., mar2012 - dec2012) as observation and gives me an error message.  For example, it reads the first row of the March data as an observation, which is in fact the header.

Should I make 11 different INFILE statements for data for each month?  Is there an optional syntax in the FILENAME statement that I can specify that the first row of each external files should be treated as header?

Thank you!

SJK

Ask a Question
Discussion stats
  • 3 replies
  • 172 views
  • 0 likes
  • 3 in conversation