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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 1132 views
  • 0 likes
  • 2 in conversation