Below code trying to resolve. However file is not reading.
%check (&date._3904_TOT_VOL_8TH_POS_OF_DCN_1_OR_GREATER_&_CURR_DCN-OB.csv);
Does the file exist where you think it is?
%put %sysfunc(fileexist(/path/users/&file.));
Does your implementation of SAS allow you to use operating system commands? If not use the FDELETE() function instead.
To capture messages from operating system command I like to use PIPE in a data step.
data _null_
infile "rm /path/users/&file." pipe;
input;
put _infile_;
run;
That way the data step can even read in the messages the command writes and then perhaps make decisions about what to do next based on what messages come back.
What is the exact name of the file involved without macro variables?
What is the current value of &date?
So it looks like the first & you want the macro processor to see and the second one you don't.
Try using %STR().
627 %let date=20210527; 628 %put &date._3904_TOT_VOL_8TH_POS_OF_DCN_1_OR_GREATER_%str(&)_CURR_DCN-OB.csv ; 20210527_3904_TOT_VOL_8TH_POS_OF_DCN_1_OR_GREATER_&_CURR_DCN-OB.csv
Use %STR() NOT %NRSTR().
Using %NRSTR() means the quoting is removed. That will cause the X command the macro generates to try to find the macro variable &_CURR_DCN.
Does the file exist where you think it is?
%put %sysfunc(fileexist(/path/users/&file.));
Does your implementation of SAS allow you to use operating system commands? If not use the FDELETE() function instead.
To capture messages from operating system command I like to use PIPE in a data step.
data _null_
infile "rm /path/users/&file." pipe;
input;
put _infile_;
run;
That way the data step can even read in the messages the command writes and then perhaps make decisions about what to do next based on what messages come back.
@SahooP wrote:
However, I am notable to delete the file using Macro code.
So now you have to share the code of the macro to show how your are attempting to delete the file and maybe should show the log of your attempt.
Some common issues: you show a file name but do you attempt to delete that file from the correct directory (or folder or file path)?
Does the machine executing SAS have access to the folder and file? If you are working with a server version of SAS then that compute probably cannot "see" your local hard drive. And if it does see the file do you have permissions to delete files in that location (this is an operating system issue).
If using a server version of SAS the Admin may restrict you from using certain commands, which is why we should see your code and log from attempting to run the code. This means you should set the OPTION MPRINT; before running the macro to display more details in the log.
The operating system you are using may be case sensitive to file names and the value of the macro parameter does not match the case of the name the operating system recognizes.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.