Help using Base SAS procedures

Data trimmed while importing multiple csv files

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Data trimmed while importing multiple csv files

Screenshot (6).pngHi,

 

I have used the following code and macro to import mutliple csv files:

 

%let path = C:\;

filename folder "&path\ndakota0711";

libname c 'C:\Temp';

options validmemname=extend;

data county_list;

length Line 8 county_code $20;

list = dopen('folder');

do Line = 1 to dnum(List);

County_code = trim(dread(List,Line));

output;

end;

drop List Line;

run;

data nd0711;

set county_list end=final;

call symputx(cats('County_Code', _N_), trim(County_Code));

call symputx(cats('Name', _N_), trim(nliteral(substr(County_Code,1,min(32, length(County_Code)-4)))));

if final then call symputx(trim('Total'), _N_);

run;

%macro loop;

%do i = 1 %to &Total;

proc import datafile="&path\ndakota0711\&&County_Code&i"

out=c.&&name&i

dbms=csv

replace;

getnames=yes;

run;

%end;

%mend loop;

 

 

%loop

 

However, observations of the first variable "From" in all imported data sets are all trimmed or truncated (I have attached a screenshot of the output file). Can anyone help me with this.

 


Accepted Solutions
Solution
‎01-25-2018 06:01 PM
Super User
Posts: 23,683

Re: Data trimmed while importing multiple csv files

Posted in reply to abubakrayesh

Add the GUESSINGROWS=MAX option - it will take longer to run. 

Or write a data step that explicitly defines the length and type.

View solution in original post


All Replies
Solution
‎01-25-2018 06:01 PM
Super User
Posts: 23,683

Re: Data trimmed while importing multiple csv files

Posted in reply to abubakrayesh

Add the GUESSINGROWS=MAX option - it will take longer to run. 

Or write a data step that explicitly defines the length and type.

New Contributor
Posts: 4

Re: Data trimmed while importing multiple csv files

Can you tell me where to insert the data step exactly? I am new to SAS and
not very comfortable with it yet. Thanks.
Super User
Posts: 23,683

Re: Data trimmed while importing multiple csv files

Posted in reply to abubakrayesh

When you run PROC IMPORT, check your log. It has the data step to import the code. Modify the lengths/types in that code to be what you want and then use that code to import the data. 


This assumes all your data sets have the same type/format. If that's the case you can also follow the approach outlined here to import all at once into the same data set.

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

 


abubakrayesh wrote:
Can you tell me where to insert the data step exactly? I am new to SAS and
not very comfortable with it yet. Thanks.

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 264 views
  • 0 likes
  • 2 in conversation