BookmarkSubscribeRSS Feed
billfish
Quartz | Level 8

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

3 REPLIES 3
ChrisHemedinger
Community Manager

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).

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
ballardw
Super User

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.

billfish
Quartz | Level 8

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

https://communities.sas.com/t5/SAS-Data-Management/how-to-get-list-of-files-available-in-Directory-i...

and I am good.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1238 views
  • 3 likes
  • 3 in conversation