Execute shell commands with an asterisk in SAS
Linux
Coding
SAS
I wanted to use %sysexec
to execute a shell command with an asterisk (shell wildcard for globbing) in a SAS program:
{sas eval=FALSE} %sysexec cp /tmp/foo/*.txt /tmp/bar ;
However, it wasn't giving me the desired results, probably due to the /*
characters as they begin a commented section in a SAS program. Also tried escaping the asterisk with \*
and surrounding the shell command with quotes but I didn't get any luck. Emailed the SAS-L community for help and discovered the x
and call system
statements in SAS. The following works:
{sas eval=FALSE} x "cp /tmp/foo/*.txt /tmp/bar" ; /* or */ data _null_ ; call system("cp /tmp/foo/*.txt /tmp/bar") ; run ;
More information on executing shell commands in a SAS program can be found here.