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

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

6 REPLIES 6
Krueger
Pyrite | Level 9

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

 

adleach2
Fluorite | Level 6

@Krueger   Thanks that will work as well. 

Reeza
Super User

Start with %STR() and move your way forward?

 

https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p0pwrvnlcooi3tn0z3g1755ebcng.htm&docse...

 

Summary of Special Characters and Macro Quoting Functions by Item

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*

By Function

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.

adleach2
Fluorite | Level 6

@Reeza  Thank you 

 

Tom
Super User Tom
Super User

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/.    ) ;
adleach2
Fluorite | Level 6

@Tom  Thanks for clarifying the issue.   This solutions works. 

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
  • 6 replies
  • 2292 views
  • 1 like
  • 4 in conversation