BookmarkSubscribeRSS Feed
ARK72
Calcite | Level 5

So I put together a bit of code to read in a large file. The variable that I oddly need the most is only reading in the first digit. It's a tab delimited file which I have carve out just enough of as a sample to show. The variable I am most concerned about is RCON5597 which is not defined for every row. But where it is I just get that first bit and then nothing else. For example row 25 (obs 23 really) should be 314408 and I'm getting 3.

 

filename data1222 'rco1222a.txt';

proc import datafile = data1222
out = a1222
dbms = TAB replace;
getnames = yes;
datarow = 3;
run;

2 REPLIES 2
Tom
Super User Tom
Super User

If you are going to force SAS to GUESS how to read a file you could at least ask it to check the whole file before making its guesses.

 

Add this statement to the PROC IMPORT step

guessingrows=max;
ballardw
Super User

If you must read data with Proc Import it is a good idea to use the GUESSINGROWS option set to a large value.

Otherwise SAS only uses the first few rows of the file to determine types and properties of variables, often 20 rows.

If you look at your file the first row with a value for that variable is row 25. So SAS defaulted to treated the value as a one character so you could see something.

 

proc import datafile = data1222
out = a1222
dbms = TAB replace;
getnames = yes;
datarow = 3;
guessingrows=max;
run;

Proc Import guesses for each run of the program. So if you read different files that are supposed to be of the same structure you can get different variable types, lengths and in some cases variable names. So if you have multiple files it is a good idea to write a data step to read text files. Proc Import will write one, which you should see in the log. You could copy that from the log, paste into the editor and clean up such  as removing line numbers and specifying desired informats. Most of the Format statements generated won't be needed except for date, time or datetime values.

 

Another advantage of the data step is you can labels, so things like the second row of your file are associated with the variable.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 499 views
  • 0 likes
  • 3 in conversation