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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.