Dear Community ,
I am working on a macro to do some OS commands for me. I want to pass parameters to the macro that contain the character *.
However, my code doesn't work because SAS is recognizing * as the comment to end of line .
For example, my macro call looks like
%_53_os_cmd ( oscmd = cp /home/e931413/from/*.* /home/e931413/to/. ) ;
Of course the * in the first parameter causes SAS to ignore everything after that. Is there is a way I can pass the * to the macro?
Thanks!
The problem is not the * per se, but the combination of characters. In particular your statement:
%_53_os_cmd ( oscmd = cp /home/e931413/from/*.* /home/e931413/to/. ) ;
Has the start of a block comment /* which you never end.
So either add regular quotes in the call, you will probably need to add them when you use that string anyway.
%_53_os_cmd ( oscmd = "cp /home/e931413/from/*.* /home/e931413/to/. " ) ;
Or add macro quoting. You could try to quote the full thing or just the part that make it look like a comment.
%_53_os_cmd ( oscmd = cp /home/e931413/from/%str(*).* /home/e931413/to/. ) ;
Reference the path in a %let statement and then plug that in.
%let path = "cp /home/e931413/from/*.* /home/e931413/to/.";
%_53_os_cmd ( oscmd = &path.);
@Krueger Thanks that will work as well.
Start with %STR() and move your way forward?
Group |
Items |
Macro Quoting Functions |
---|---|---|
A |
+ — */<>=¬^|~;, # blank AND OR NOT EQ NE LE LT GE GT IN |
all |
B |
&% |
%NRSTR, %NRBQUOTE, %SUPERQ, %NRQUOTE |
C |
unmatched' “() |
%BQUOTE, %NRBQUOTE, %SUPERQ, %STR*, %NRSTR*, %QUOTE*, %NRQUOTE* |
Function |
Affects Groups |
Works At |
|
---|---|---|---|
%STR |
A, C* |
Macro compilation |
|
%NRSTR |
A, B, C* |
Macro compilation |
|
%BQUOTE |
A, C |
Macro execution |
|
%NRBQUOTE |
A, B, C |
Macro execution |
|
%SUPERQ |
A, B, C |
Macro execution (prevents resolution) |
|
%QUOTE |
A, C* |
Macro execution. Requires unmatched quotation marks and parentheses to be marked with a percent sign (%). |
|
%NRQUOTE |
A, B, C* |
Macro execution. Requires unmatched quotation marks and parentheses to be marked with a percent sign (%). |
|
*Unmatched quotation marks and parentheses must be marked with a percent sign (%) when used with %STR, %NRSTR, %QUOTE, and %NRQUOTE. |
@Reeza Thank you
The problem is not the * per se, but the combination of characters. In particular your statement:
%_53_os_cmd ( oscmd = cp /home/e931413/from/*.* /home/e931413/to/. ) ;
Has the start of a block comment /* which you never end.
So either add regular quotes in the call, you will probably need to add them when you use that string anyway.
%_53_os_cmd ( oscmd = "cp /home/e931413/from/*.* /home/e931413/to/. " ) ;
Or add macro quoting. You could try to quote the full thing or just the part that make it look like a comment.
%_53_os_cmd ( oscmd = cp /home/e931413/from/%str(*).* /home/e931413/to/. ) ;
@Tom Thanks for clarifying the issue. This solutions works.
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.