BookmarkSubscribeRSS Feed
Pyrite | Level 9

Hello, I have another problem when importing my CSV file into SAS

There is a variable "State", and most of the values are like PA, NJ, NY, etc, but there a few cases they are using "New York", "New Jersey" etc. I can see these im excel. But when I imported into SAS, they were truncated as "Ne".


I can edit the CSV file before importing. But I wonder if there is a way to handle this more efficiently so I do not need to eidt the CSV in Excel manually? The fils is pretty charge (more than 1 million cases), so I hope I can find a better way.


Thank you in advance!

Barite | Level 11

One option: you can increase the scaned rows from the input file to determine the appropriate data type and length of columns. By adding the option guessingrows = 32767 (maximum for Base SAS 9.2 ) or more till 2147483647 (maximum for Base SAS 9.3 and later)

For example:




Pyrite | Level 9
Thank you. I am using 9.4, so I can use the larger number. Hope this will work. Will try tomorrow when I back to work.
Barite | Level 11

You should be consider that this option come with performance penalty for the scanning, even if it is easier. The best way is to run PROC IMPORT on your data set then copy the generated DATA step from the log and increase your column length which is truncated, then run this DATA step after your modifications. This could be the best solution as it is work environment and your dataset tend to be big one.

Super User
Second option is to read your file via a data step rather than use proc import. This way you can specify the length/format. If your file is CSV then you can check the log for the code, copy and paste that and modify as necessary.
Pyrite | Level 9
Thank you. I can give it a try.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


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
  • 5 replies
  • 3 in conversation