Hi,
I would like to import csv to sas table but I have problem with column length. It seems that column data type(length) is set according to the first row.
For example the csv file(name.csv) looks like this:
+---------+-------------+
| cust_id | Name |
+---------+-------------+
| 1 | King |
| 2 | Smith |
| 3 | Brown |
I will use this code for import:
proc import datafile="\\inputs\name.csv"
out=lib.tablename dbms=csv replace;
getnames=yes;
run;
And the result in the lib.tablename is:
+---------+-------------+ | cust_id | Name | +---------+-------------+ | 1 | King | | 2 | Smit | | 3 | Brow |
The last letter in a second and third row is deleted... Is there any way how to format column in proc import? Or may I use something else than proc import?
Thanks
There is an option in proc import. Try to add before the run; GUESSINGROWS=X. This means that the format should be applied after X rows readed
There is an option in proc import. Try to add before the run; GUESSINGROWS=X. This means that the format should be applied after X rows readed
Thank you very much. It works 🙂
This method does not work for me, the log said unsuccessful.
my code is as following:
proc import datafile="\\sf...... ..csv"
out=adeg DBMS=csv replace;
GUESSINGROWS=2;
run;
revised the code to gussingrows=42 , then it works, thanks! it needs to be the row which has longest word, got it!
As an alternaitve, take responsibility for setting the data strcuture yourself - being the best person to know what that should be like, and don't rely on SAS proc import to guess what the data should look like.
data want; infile "<your csv file>.csv"; length var1 $200 var2 8; format var1 $200 var2 8.; informat var1 $200 var2 8.; input var1 $ var2; run;
You can get the actual program generated by proc import from your log, then you can modify that to meet your needs (or modify it to your data import agreement which details the specification of the imported data).
yeah, by revising log code, the column length could be adjusted. Thanks!
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!
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.