Hi,
Im trying to create a test file with today date in Linux from SAS program using the below query , but I'm not able to result.
X "bhosts | sed 's/ /,/g' | sed 's/,\{2,\}/,/g' > /home/test_"$(date +%%F)".txt";
But I when I run directly in Linux the below query its working.
bhosts | sed 's/ /,/g' | sed 's/,\{2,\}/,/g' > /home/test_"$(date +%F)".txt
Whether variable will not able to be passed in X command???
Thanks.
Try this:
X "bhosts | sed 's/ /,/g' | sed 's/,\{2,\}/,/g' > /home/test_%sysfunc(today(),yymmddd10.).txt";
Do you really want those double quotes in the filename?
Change the X command to the %PUT statement so you can try to see what you are trying to pass to the X command.
704 %put "bhosts | sed 's/ /,/g' | sed 's/,\{2,\}/,/g' > /home/test_"$(date +%%F)".txt"; "bhosts | sed 's/ /,/g' | sed 's/,\{2,\}/,/g' > /home/test_"$(date +%%F)".txt"
So you have given the X command a quoted string that starts with bhosts and ends with test_, then the unquoted characters $(date +%%F) and then the quoted string .txt. Note that %F looks like a macro call. Do you actually have a macro named F to call?
Would be much better to wrap the command inside of single quotes to prevent the macro processor from trying to interpret the & and % characters. Since your command already had single quotes in it you need to double them.
x 'bhosts | sed ''s/ /,/g'' | sed ''s/,\{2,\}/,/g'' > /home/test_"$(date +%F)".txt' ;
Or convert them to double quotes instead.
x 'bhosts | sed "s/ /,/g" | sed "s/,\{2,\}/,/g" > /home/test_"$(date +%F)".txt' ;
Looks like you are running the bhosts command and piping the results to a file. Why not just use a data step instead?
data _null_;
infile 'bhosts' pipe;
file "/home/test/%sysfunc(date(),yymmdd10).txt";
input;
_infile_=tranwrd(translate(_infile_,',',' '),'{2,}',',');
put _infile_;
run;
+%F is a format qualifier that directs date to output a full format (YYYY-MM-DD).
I think that the double quotes around the date call are a mistake, as are the double percent signs. When running this command from SAS, I'd let SAS compute the date.
Try this:
X "bhosts | sed 's/ /,/g' | sed 's/,\{2,\}/,/g' > /home/test_%sysfunc(today(),yymmddd10.).txt";
Thanks @Kurt_Bremser .It was successful with your query. .
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.