DATA Step, Macro, Functions and more

problem in importing csv files to SAS, state "New york" was read in as "Ne"

Reply
Super Contributor
Posts: 312

problem in importing csv files to SAS, state "New york" was read in as "Ne"

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!

Super Contributor
Posts: 490

Re: problem in importing csv files to SAS, state "New york" was read in as "Ne"

[ Edited ]

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:

 

PROC IMPORT DATAFILE=REFFILE
	DBMS=CSV
	OUT=WORK.IMPORT
	guessingrows=32767;
RUN;

 

Super Contributor
Posts: 312

Re: problem in importing csv files to SAS, state "New york" was read in as "Ne"

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.
Super Contributor
Posts: 490

Re: problem in importing csv files to SAS, state "New york" was read in as "Ne"

[ Edited ]

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
Posts: 17,784

Re: problem in importing csv files to SAS, state "New york" was read in as "Ne"

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.
Super Contributor
Posts: 312

Re: problem in importing csv files to SAS, state "New york" was read in as "Ne"

Thank you. I can give it a try.
Ask a Question
Discussion stats
  • 5 replies
  • 197 views
  • 0 likes
  • 3 in conversation