Rename a external file in a SAS macro

Victor

I am getting a generic 'Statement not valid or out of order' message with the below:

%macro test;
data _null_;
%if %sysfunc(fileexist("C:\report_201809.xlsx")) = 1 %then %do;
rc=%sysfunc(rename("C:\report_201809.xlsx",
"C:\report_201809.xlsx"_old.xlsx",'file'));
%end;
%mend;

%test;
J_Lard

The code below should get you what you need. While you can use %if statements in a data step you generally won't need to. I'm guessing the error is coming from the %sysfunc function around the fileexist and rename functions. %sysfunc allows you to call data step functions outside of a data step so it is not needed here.

%macro test;
data _null_;
if fileexist("C:\file.txt") then do;
    rc = rename("C:\file.txt", "C:\file2.txt", 'file');
end;
run;
%mend;

Alternatively, you could use an X Command that allows you to execute Windows commands. You could replace the rename function with the following statement.

x move C:\file.txt C:\file2.txt;

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

TOP lista

quentelabel

Arquivo