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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Reeza
Super User

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

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

abubakrayesh
Fluorite | Level 6
Can you tell me where to insert the data step exactly? I am new to SAS and
not very comfortable with it yet. Thanks.
Reeza
Super User

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.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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