BookmarkSubscribeRSS Feed
Nikolasas
Calcite | Level 5

Hello I am trying to import csv files in my work library.

 

%let directory = E:\saved ;

filename files pipe "dir /b &directory\*.csv";

 

data file_list;
length file_name $40;
infile files length=reclen;
input file_name $varying40. reclen;
run;

 

 

%macro csv;

 

proc sql noprint;
select count(*) into :vol_of_files
from work.file_list;
quit;

 

%do i=1 %to &vol_of_files.;

 

data work.file_list_v2;
set work.file_list (firstobs = &i.);
run;

 

proc sql outobs=1;
create table work.file_list_v3 as
select *
from work.file_list_v2;
quit;

 

proc sql;
select * into :file_name
from work.file_list_v3;
quit;

 

data file_list_v4 (keep=file_name_new);
set file_list_v3;
file_name_new = reverse(substr(reverse(&file_name.),5));
run;

 

proc sql;
select * into :file_name_v2
from work.file_list_v4;
quit;

 

proc import out=&file_name_v2.
datafile="&directory.\&file_name."
dbms=csv replace;
getnames=yes;


run;


%end;
%mend csv;
%csv

 

The idea that I had, was to store the file names into a table file_list as values of a variable file_name.

Later I find the length of the table, and I want to iterate thought the values of this column. My logic gives an error and I am not sure.

Any suggestions?

 

Thanks

3 REPLIES 3

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1126 views
  • 0 likes
  • 2 in conversation