Move files from file names in dataset.

Reply
New Contributor
Posts: 2

Move files from file names in dataset.

Hello. I am trying to create a workflow that reads in a list of files from a system folder, filters the list based on a few other tables, and then provides a list of files that should be moved to another folder.

 

I am having trouble with the last part of this workflow. The dataset that results from the filter contains a single column named FileName which contains files needing to be moved.

 

(filename example: Last, First EmployeeID.TIF)

 

I’ve tried a few solutions like creating a macro scan loop and calling an x command, but each solution I come up with either crashes or fails to move all/any of the files. Any help with this would be great. Here is my latest iteration that tends to just make SAS crash.

 

PROC SQL;
   CREATE TABLE WORK.UNIQ_NEW AS 
   SELECT DISTINCT 
      CATT('"\\nas\KDrive\EFAX\',t1.FileName,'"') AS FileName
      FROM WORK.New t1
      ORDER BY t1.FileName;
QUIT;

/* Macro to SCAN through DATALOG */
%MACRO SCANLOOP(SCANFILE,FIELD1);
    %LET actioncmd = copy;
	%LET destination = "\\nas\\NGH\Forms - New";
	%LET separator_s =%str( );

	DATA _NULL_;
		IF 0 THEN SET &SCANFILE NOBS=X;
		CALL SYMPUT('RECCOUNT',X);
		STOP;
	RUN;

	%DO I=1 %TO &RECCOUNT;

		DATA _NULL_;
			SET &SCANFILE (FIRSTOBS=&I);
			CALL SYMPUT('VAR1',&FIELD1);
			STOP;
		RUN;

		%LET command = %sysfunc(catx(&separator_s,&actioncmd,&VAR1,&destination));
		x &command;

	%END;
%MEND SCANLOOP;
/* Call SCANLOOP */
%SCANLOOP(WORK.UNIQ_NEW,FileName);
RUN;
Super User
Super User
Posts: 9,599

Re: Move files from file names in dataset.

Posted in reply to NGHAnalyst

Can you post example of test data of have - in the for of a dataset.  Then show what you want at the end.  I.e. do you want a text file with those names or a dataset - a macro list is not good - you can see that for all the extra code you have to provide.  Also please avoid coding all in shouting, it makes reading code very hard.

It seems like you just want a stream of copy commands put out at the end, so maybe something like:

data _null_;
  length comm $2000;
  set new;
  comm=cat('%sysexec copy "\\nas\KDrive\EFAX\',strip(filename),'" "\\nas\ngh\forms - new");
  call execute(comm);
run;
New Contributor
Posts: 2

Re: Move files from file names in dataset.

Thank you so much for your help and advise! That worked perfectly. 

Ask a Question
Discussion stats
  • 2 replies
  • 64 views
  • 0 likes
  • 2 in conversation