DATA Step, Macro, Functions and more

proc import problem with column length

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

proc import problem with column length

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

 


Accepted Solutions
Solution
‎07-15-2016 06:16 AM
Frequent Contributor
Posts: 144

Re: proc import problem with column length

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


All Replies
Solution
‎07-15-2016 06:16 AM
Frequent Contributor
Posts: 144

Re: proc import problem with column length

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

Occasional Contributor
Posts: 15

Re: proc import problem with column length

Posted in reply to arodriguez

Thank you very much. It works Smiley Happy

Super User
Super User
Posts: 7,970

Re: proc import problem with column length

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

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 2268 views
  • 2 likes
  • 3 in conversation