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

I'm sure I resolved this once before when dealing with URIs but I cannot for the life of me get this to work.

 

I don't like warnings, and the array of % symbols in this Unix command are causing about 15 warnings per loop.

 

Example code which is contained within a DO loop in a %MACRO:

data _null_;
ps = %nrstr("ssh -o StrictHostKeyChecking=no ""&ServerName"" 'find /logdir/ -type f -printf ""%p|%TY-%Tm-%Td %TX|%AY-%Am-%Ad %AX|%s|%u|%U\n"" > &projDir./Data/output.&ServerName'");
call system(ps);
;run;

 

When using NRSTR, the call system cannot resolve the entry "ps" which is created directly above it. I've also tried the same with a %let statement and then using call system(&ps.) but still, nothing.

 

BQUOTE, NRBQUOTE, STR, etc, etc do not remove warnings (and in some cases, BQUOTE particularly, I get errors).

 

Does anyone have a working example where they have been able to construct a command with "'s, 's %'s and other symbols and can then execute against it?

 

The closest I have got to a clean log is with NRSTR, but the output cannot be executed against.

 

 

Thanks in advance,

 

Dan

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

I don't have a working example, but I do have a suggestion.

 

Note that single quotes suppress all macro activity, while double quotes permit macro activity (needed to allow &ServerName to resolve).

 

Here's an untested attempt at what you might be able to use to do this:

 

data _null_;

ps = cat("ssh -o StrictHostKeyChecking=no ""&ServerName"" 'find /logdir/ -type f -printf ",

         '"%p|%TY-%Tm-%Td %TX|%AY-%Am-%Ad %AX|%s|%u|%U\n"',

         " > &projDir./Data/output.&ServerName'");

 

It looks like @RW9 and I are thinking along similar lines.  You might need to see what the values are that get assigned to PS, and tweak the results (such as where the quotes go) since our suggestions are similar but not identical.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

That code will not work as you are mixing datastep and macro code.  %nstr() is a macro itself.  With the data _null_ you already have the ability to process the data fully in a string:

data _null_;
  ps=cat('"ssh -o StrictHostKeyChecking=no ',"&ServerName",' find /logdir/ -type f -printf "%p|%TY-%Tm-%Td %TX|%AY-%Am-%Ad %AX|%s|%u|%U\n" > ',"&projDir.",'/Data/output.',"&ServerName",'"');
  call system(ps);
run;

Or something along those lines.  Basically I am just concatenating the various parts of the string together using Base SAS string functions to get it looking as I want.

Astounding
PROC Star

I don't have a working example, but I do have a suggestion.

 

Note that single quotes suppress all macro activity, while double quotes permit macro activity (needed to allow &ServerName to resolve).

 

Here's an untested attempt at what you might be able to use to do this:

 

data _null_;

ps = cat("ssh -o StrictHostKeyChecking=no ""&ServerName"" 'find /logdir/ -type f -printf ",

         '"%p|%TY-%Tm-%Td %TX|%AY-%Am-%Ad %AX|%s|%u|%U\n"',

         " > &projDir./Data/output.&ServerName'");

 

It looks like @RW9 and I are thinking along similar lines.  You might need to see what the values are that get assigned to PS, and tweak the results (such as where the quotes go) since our suggestions are similar but not identical.

_Dan_
Quartz | Level 8

Hi there, thanks for your responses

Single and double quoting isn't an unknown factor for me, so I'm happy with the understanding of how a macro variable will not be resolved within single quotes, which is what caused further issues because I could have wrapped the whole thing in single quotes and the issue would have gone away...

@Astounding has provided a working solution, as it concatenates a working string within single quotes without physically wrapping it in single quotes, therefore the macro variables resolve, and the %s are hidden, which is exactly what I needed.

Thanks again to both of you for your help.


Dan

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 381 views
  • 0 likes
  • 3 in conversation