BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Vendy
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
arodriguez
Lapis Lazuli | Level 10

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

View solution in original post

6 REPLIES 6
arodriguez
Lapis Lazuli | Level 10

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

Vendy
Obsidian | Level 7

Thank you very much. It works 🙂

mlin828
Calcite | Level 5

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;

 

 

mlin828
Calcite | Level 5

revised the code to gussingrows=42 , then it works, thanks! it needs to be the row which has longest word, got it!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).  

 

mlin828
Calcite | Level 5

yeah, by revising log code, the column length could be adjusted. Thanks!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 52225 views
  • 2 likes
  • 4 in conversation