BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5

Reg:Shell X command

Actually i want to execute sheel script if the day=6

i am doing like this

data _null_;
if &day=6;
then do;
x 'new.sh';
x 'old.sh';
end;
run;

If i keep like this is was working on all the days acutally &day i my macro variable
from a dataset it was not resoving properly how can i do it.

4 REPLIES 4
manojinpec
Obsidian | Level 7

Hi,

My_SAS since the comparison is onmacro variable the condition should be macr condition and would involve macr if condition:-

data _null_;


%if &day=6;
%then %do;
x 'new.sh';
x 'old.sh';
%end;
run;

try this..

My_SAS
Calcite | Level 5

actually is there any way for the x command to execute the shell script if it satisfy the contion i have given

KarlK
Fluorite | Level 6

I have not tested this, but just looking at your code, it appears you have an extra semicolon. Try it without the semicolon after the "6". In other words:

if &day = 6 then do;

Karl

FriedEgg
SAS Employee

X statment cannot be executed from in a datastep.  It can be executed conditionally through a macro as shown above.

In a datastep, use call system, or call execute with the x command inside.

data _null_;

if &day=6 then do;

call system('/path/to/new.sh');

call execute('x /path/to/old.sh');

end;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 781 views
  • 0 likes
  • 4 in conversation