BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

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!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

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
  • 2 replies
  • 5341 views
  • 0 likes
  • 3 in conversation