Published on :

System File Copy Macro (AHGtoSDD)

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
This macro checks for the existence of a source file specified by the 'from' parameter. If the file exists, it executes a system command via the 'x' instruction to copy it to the 'to' destination, potentially renaming it. The system command syntax ('copy', use of backslashes, '/y' flag) is specific to Windows environments and may require adaptation for a SAS© Viya environment on Linux. The code also depends on an external macro '%AHGfilename'. The use of the 'x' command requires the XCMD option to be enabled on the server.
Data Analysis

Type : EXTERNE


The script manipulates physical files directly via the operating system, without using SAS libraries.

1 Code Block
MACRO
Explanation :
Macro definition. It declares local variables, calls a utility macro (%AHGfilename), checks for the existence of the source file with %sysfunc(fileexist), and executes the copy via an 'x' shell command if the condition is met.
Copied!
1%macro AHGtoSDD(from,to,rename=);
2 
3%local filename toname;
4%let filename=%AHGfilename(&from);
5 
6 
7%IF %sysfunc(fileexist(&from)) %THEN x "copy &from &to\&rename/y";
8 
9%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.