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;
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;
Thank you so much for your help and advise! That worked perfectly.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.