DATA Step, Macro, Functions and more

force proc import to make column numeric

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

force proc import to make column numeric

I am currently using this code:

 

proc import datafile="&BaseFolder.&FileName." 
out=LatestData replace;
guessingrows=10000;
run;

In most scenarios this works fine for a column X if it contains a number in the first 10000 rows. Sometimes my file's column is empty. How can I force proc import to use a numeric datatype for column X? Thanks!

 

 


Accepted Solutions
Solution
‎05-18-2017 01:08 PM
Super User
Posts: 11,343

Re: force proc import to make column numeric

Posted in reply to csetzkorn

If your files referenced &BaseFolder.&FileName are supposed to have the same structure then they should be read with a data step where you have control.

Proc Import is a guessing procedure and apparently the behavior is to guess that a column with missing values is character.

A minor suggestion would be to bump the guessing rows up to 32000 but that may not help.

View solution in original post


All Replies
Solution
‎05-18-2017 01:08 PM
Super User
Posts: 11,343

Re: force proc import to make column numeric

Posted in reply to csetzkorn

If your files referenced &BaseFolder.&FileName are supposed to have the same structure then they should be read with a data step where you have control.

Proc Import is a guessing procedure and apparently the behavior is to guess that a column with missing values is character.

A minor suggestion would be to bump the guessing rows up to 32000 but that may not help.

Super User
Super User
Posts: 7,977

Re: force proc import to make column numeric

Posted in reply to csetzkorn

Right, proc imoprt is a Guessing Procedure.  It looks at the file and Guesses what the data looks like.  If you don't like its guess then its time for you to put the effort in to specify what each column should be.  Never rely on guessing procedures.  You can take the datastep code which proc import creates in the log, and then modify that to your needs, so it would look like:

data want;
  infile "your-file";
  length  ...;
  informat ...;
  format ...;
  input ...;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 122 views
  • 0 likes
  • 3 in conversation