BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SahooP
Fluorite | Level 6

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);

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

9 REPLIES 9
ballardw
Super User

What is the exact name of the file involved without macro variables?

What is the current value of &date?

Tom
Super User Tom
Super User

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

 

 

SahooP
Fluorite | Level 6
options symbolgen mprint;
%macro check(file);
X "rm /path/users/&file.";
%mend check;

/*%check(file = 20210524_3904_TOT_RECS_MSTR_DS6_NEW_ADD-CHG_REC-OLD_SPH0_REC.csv); */
%check (20210524_3904_TOT_VOL_8TH_POS_OF_DCN_1_OR_GREATER_%nrstr(&)_CURR_DCN-OB.csv);


I am not able to resolve.
Tom
Super User Tom
Super User

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.

SahooP
Fluorite | Level 6
33 /*%check(file = 20210524_3904_TOT_RECS_MSTR_DS6_NEW_ADD-CHG_REC-OLD_SPH0_REC.csv); */
34 %check (20210524_3904_TOT_VOL_8TH_POS_OF_DCN_1_OR_GREATER_%str(&)_CURR_DCN-OB.csv);
MLOGIC(CHECK): Beginning execution.
MLOGIC(CHECK): Parameter FILE has value 20210524_3904_TOT_VOL_8TH_POS_OF_DCN_1_OR_GREATER_&_CURR_DCN-OB.csv
MLOGIC(CHECK): Ending execution.
SahooP
Fluorite | Level 6
However, I am notable to delete the file using Macro code.
Tom
Super User Tom
Super User

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.

ballardw
Super User

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1892 views
  • 1 like
  • 3 in conversation