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
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;
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.
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: