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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 867 views
  • 1 like
  • 4 in conversation