BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ijmoorejr
Calcite | Level 5

The logic in the attached code block is working with the exception of the X command. Ideally, the X command to execute another SAS program should only run if varfroma=varfromb, but it keeps running even when varfroma ne varfromb. The put statements work properly, but the X command keeps running regardless of whether or not varfroma and varfromb are equal and seems to ignore the if/then/do logic. Can anyone suggest a way to fix this issue? Thanks.

libname datalib '/users/data/lives/here';
data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
x 'sas /users/prog/lives/here/runme.sas';
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Afaik the x command can't be executed conditionally. And it is a bit strange to call a sas program in a sas program using os-commands. What are you trying to do? You could, of course, replace the x command with call system.

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

Afaik the x command can't be executed conditionally. And it is a bit strange to call a sas program in a sas program using os-commands. What are you trying to do? You could, of course, replace the x command with call system.

ijmoorejr
Calcite | Level 5

Thank you, andreas_lds. Using call system worked.

SASKiwi
PROC Star

There are a few ways of doing this. Here is one:

 

libname datalib '/users/data/lives/here';

%let run_pgm =;

data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
call symput('run_pgm', '%include "sas /users/prog/lives/here/runme.sas";');
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;

&run_pgm
Kurt_Bremser
Super User

First of all, X is not a data step statement, but a global statement. Which means it takes effect immediately when it is encountered in the program text, not when that program text is executed after compilation.

Your code is equivalent to

x 'sas /users/prog/lives/here/runme.sas';
data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;

Also mind: if you use call system here (which is a data step call routine), you would execute the external program for EVERY mismatch, which is probably not what you want.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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