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

Hello everyone,

 

i want to run the code based on certain conditions, lets say if the sex="M" then it will run the whole code

other wise it will run the other codes.

 

my code contain different macros and data step programs and sql quries as well.

 

Thanks in Advane

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You can use next skiltom:

%macro(choose);
     data _null_;
       set any_data;
             if <condition> 
                then call symput('flag',1);
                else call symput('flag',0);
     run;
     
     %if &flag = 1 %then do;
           <program 1>
     %end; %else %do;
          <program 2>
      %end;
%mend;
%choose;

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

Does the condition relate to your data (where=(var=value)) or to external info (like date of run) ?

 

shivamarrora0
Obsidian | Level 7
it can be either of 1 , what i want is to execute whole code on based on single condition, if the condition is false then i want to execute the other code
Shmuel
Garnet | Level 18

You can use next skiltom:

%macro(choose);
     data _null_;
       set any_data;
             if <condition> 
                then call symput('flag',1);
                else call symput('flag',0);
     run;
     
     %if &flag = 1 %then do;
           <program 1>
     %end; %else %do;
          <program 2>
      %end;
%mend;
%choose;
ballardw
Super User

Can you show what type of code you are expecting to do this for?

 

Within a data step is one thing but if you need to do this with multiple procs and such that is another set of potential headaches.

other code

 


@shivamarrora0 wrote:
it can be either of 1 , what i want is to execute whole code on based on single condition, if the condition is false then i want to execute the other code

I am not sure what "either of 1" means in this context. And what is "whole code"? Examples go a long way to clarifying questions.

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 838 views
  • 0 likes
  • 3 in conversation