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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1472 views
  • 0 likes
  • 4 in conversation