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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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