Help using Base SAS procedures

CSV TO DATASET

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

CSV TO DATASET

I have CSV file. I am importing into SAS dataset using proc import but as result some of the data is truncated…can someone suggest if there is any better way importing……

PROC IMPORT OUT=mydata

   DATAFILE="/c/clean.csv"

       DBMS=CSV REPLACE;

     delimiter = ";"; 

   GETNAMES=YES;

    DATAROW=2;

RUN;


Accepted Solutions
Solution
‎08-29-2014 11:11 AM
Super User
Posts: 11,343

Re: CSV TO DATASET

Posted in reply to rakeshvvv

add guessingrows=32000 option if you must use proc import. There is a default number of rows SAS will use to determine type and length of variables. If you have longer text after that number of rows then it is likely to get truncated. The guessingrows option tells SAS to look at more lines before setting type and length.

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: CSV TO DATASET

Posted in reply to rakeshvvv

Yes, use datastep (there are lots of examples on the communities):

data want;

     length var1-var4 $10;

     infile "c:\clean/.csv" dsd missover dlm="," lrecl=32767; /* Change DLM to semicolon if needed */

     input var1 $ var2 $ var3 $ var4 $;

run;

Obviously change the varx and format to what it is in your data, i.e. if you have dates and things, add formats, informats.

Respected Advisor
Posts: 3,799

Re: CSV TO DATASET

Posted in reply to rakeshvvv

rakeshvvv wrote:

some of the data is truncated…

Seems a bit vague.

Solution
‎08-29-2014 11:11 AM
Super User
Posts: 11,343

Re: CSV TO DATASET

Posted in reply to rakeshvvv

add guessingrows=32000 option if you must use proc import. There is a default number of rows SAS will use to determine type and length of variables. If you have longer text after that number of rows then it is likely to get truncated. The guessingrows option tells SAS to look at more lines before setting type and length.

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 217 views
  • 3 likes
  • 4 in conversation