BookmarkSubscribeRSS Feed
Liane
Calcite | Level 5

Hi.

I'm trying to use the proc import to import a txt file but some character variables are staying incompletes in the dataset (e.g. 1 character). The code that I'm using is: 

 

 

PROC IMPORT OUT= import.results
            DATAFILE= "O:\Results2018"
            DBMS=TAB REPLACE;
     GETNAMES=YES;
     DATAROW=2;
RUN

 

Suggestions to define the number of characters?

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a datastep import, then specify the lengths, formats, informats that you know the data should have.  This is the best scenario.  You change guessingrows to a large number, but its still going to be guessing the data.

proc import...;
  guessingrows=2000;
...
run;

Note that more rows mean more resources needed.  Far better to just do:

data import.results;
  infile "o:\results2018.txt" dlm="0a"x;
  length ...;
  informat ...;
  format ...;
  input ...;
run;

This is what proc import generates (you can take it from your log and modify it rather than typing it all in).

 

Some notes:

Text data with a tab delimiter is not a CSV file!!

You filename does not have a file extension.  As a text file it should have something like .txt

Please avoid coding all in uppercase.

 

SuryaKiran
Meteorite | Level 14

The best approach for importing the data when its in .txt file is using a Data step, because you will have control over the variable attributes. Where as PROC IMPORT works on guessing the data types. By default proc import scans first 20 records and decide the data types for the variables. For example when if you have a variable where first 50 records have length of 8 and later 50 then when importing you might get the values truncated after the first 50 records because SAS will set the length based on the first 20 records. 

 

If you wish to use PROC IMPORT then use GUESSINGROWS=MAX or else you can switch to Data Step.

 

FYI: https://documentation.sas.com/?docsetId=proc&docsetTarget=p13kvtl8ezj13in17i6m99jypcwi.htm&docsetVer...

Thanks,
Suryakiran

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3103 views
  • 1 like
  • 3 in conversation