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

Hi,

 

A brief description of my intent: I'm scanning file systems across several Unix servers. The Unix command is created dynamically in a Macro and used to be submitted via 'call systask'. I want to submit the statements in parallel, so now I'm going to use 'systask command nowait'.

 

As I'm no long using the data _null_ with call systask I'm now building the Unix command in a fairly straightforward (but admittedly messy) %let statement.

 

The command works, however, the Unix command contains the percent % symbol and so the macro processor is trying to resolve things that don't exist. I know I can use %nrstr() to resolve this (that's what I did with call systask) but this is not masking anything within the %let / systask command statement.

 

It's a simple loop macro, but here's the line that builds the Unix command:

%let cmd = ssh -o StrictHostKeyChecking=no %sysfunc(quote(%sysfunc(scan(&server.,&i.,|)))) "find &dir. -type f -exec stat -c %nrstr('%n|%y|%x|%s|%U|%u|%G') {} \%nrstr(;)" > &projDir./Data/&fname.Logs_%sysfunc(scan(&server.,&i.,|)).txt;
systask command %sysfunc(quote(&cmd.)) nowait;

When it's compiled It looks like this:

ssh -o StrictHostKeyChecking=no "servername" "find /dir1/dir2/dir3/ -type f -exec stat -c '%n|%y|%x|%s|%U|%u|%G' {} \;"" > /dir1a/dir2a/dir3a/filename_servername.txt

 

This code may send shivers down the spine of more seasoned coders - I have got myself in a rut because I've had to try all sorts of different methods to get this to work, so the code is admittedly not as efficient or tidy as I'd like.

 

Any help regarding the forcible masking of the percent symbols is appreciated.

 

 

Dan

1 ACCEPTED SOLUTION

Accepted Solutions
_Dan_
Quartz | Level 8

I've found the resolution: superq.

 

Here's the end result.

 

%let cmd = ssh -o StrictHostKeyChecking=no %sysfunc(quote(%sysfunc(scan(&server.,&i.,|)))) "find &dir. -type f -exec stat -c %nrstr('%n|%y|%x|%s|%U|%u|%G') {} \%nrstr(;)" > &projDir./Data/&fname.Logs_%sysfunc(scan(&server.,&i.,|)).txt;
systask command "%superq(cmd)" nowait; 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

I would unload the whole UNIX code into a shell script that accepts all variable parts from the commandline ($1, $2 and so on). That way SAS never sees the format parameters etc, which are fixed in the script.

Create a control table with all the information (server, diractory, file names), build the commandline in a data _null_ step, and use call execute to call the systask statement.

_Dan_
Quartz | Level 8
Thanks for your reply & that's certainly a good option. I will need to consider it as a "last resort" of sorts until I've exhausted any options on coding it directly into the SAS Macro.
_Dan_
Quartz | Level 8

I've found the resolution: superq.

 

Here's the end result.

 

%let cmd = ssh -o StrictHostKeyChecking=no %sysfunc(quote(%sysfunc(scan(&server.,&i.,|)))) "find &dir. -type f -exec stat -c %nrstr('%n|%y|%x|%s|%U|%u|%G') {} \%nrstr(;)" > &projDir./Data/&fname.Logs_%sysfunc(scan(&server.,&i.,|)).txt;
systask command "%superq(cmd)" nowait; 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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