The Copy-Files task allows one to import several files from a network shared drive in one step.
After the Copy-Files task is done, the project goes to the next step (program step)
What SAS code can i use to create a SAS dataset listing the original filenames that I imported through the Copy-Files task?
Is there a way one can access programmatically the Copy-Files log file?
thanks
You can't use code to get to the Copy Files log. But you can capture filenames from a step that imports multiple files.
If you're following along with my example in this video, my code is this:
filename viewing "&codepath.../NetflixData/*.csv";
data viewing;
length title $ 300 date 8
maintitle $ 60 episode $ 40 season $ 12
profile $ 40 in $ 250;
informat date mmddyy.;
format date date9.;
infile viewing dlm=',' dsd filename=in firstobs=2;
profile=scan(in,-1,'\/');
input title date;
array part $ 60 part1-part4;
do i = 1 to 4;
part{i} = scan(title, i, ':',);
if (find(part{i},"Season")>0)
then do;
season=part{i};
end;
end;
drop i;
maintitle = part{1};
episode = part{3};
if Title ^= "Title";
run;
I use the FILENAME= option on the INFILE statement to capture the name of the input file, and then the SCAN function to get just the last part of the filename to store in the data set (profile variable in my case).
I don't use EG much but you might be able to get what you need from the SASHELP.VEXTFL view. Maybe. I know that it should have all of the Filerefs currently assigned and the path associated.
It may be some SAS OPTION which is not turned on or the way SAS EG (version 7.1) is set up.
Looking at the code below,
FILENAME = INX
works fine.
However in code line: FILE_NAME = INX , INX becomes a 8-character string so the SCAN function is not the issue.
I have no idea why INX became a 8-character string; I am still awaiting a response from the SAS Administrator.
CODE (START)
FILENAME import_a "&SASDRV./Study*.txt";
DATA F_LIST;
LENGTH FILE_NAME $100
first_var $250;
FORMAT
first_var $CHAR250.;
INFORMAT
first_var $CHAR250.;
INFILE import_a
FILENAME = INX
FIRSTOBS = 2
LRECL = 800
ENCODING = "LATIN1"
DLM = '09'x
MISSOVER
DSD ;
FILE_NAME = INX;
/* FILE_NAME = SCAN(INX,-1,'/\'); */
INPUT
first_var : $CHAR250.;
RUN;
CODE (END)
My solution is to assign the designation folder in the Copy-Files task not to WORK/XXX but to my own libname on the SAS server.
I then run an x command (UNIX) to list all text files in my libname.
I then modified a code snippet from SAS.Communities.com
and I am good.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.