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

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
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.

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!

SAS Enterprise Guide vs. SAS Studio

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.

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