Run the whole code on the base of condition

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Run the whole code on the base of condition

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


Accepted Solutions
Solution
‎03-31-2018 11:54 PM
Trusted Advisor
Posts: 1,837

Re: Run the whole code on the base of condition

Posted in reply to shivamarrora0

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


All Replies
Trusted Advisor
Posts: 1,837

Re: Run the whole code on the base of condition

Posted in reply to shivamarrora0

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

 

Contributor
Posts: 45

Re: Run the whole code on the base of condition

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
Solution
‎03-31-2018 11:54 PM
Trusted Advisor
Posts: 1,837

Re: Run the whole code on the base of condition

Posted in reply to shivamarrora0

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;
Super User
Posts: 13,523

Re: Run the whole code on the base of condition

Posted in reply to shivamarrora0

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.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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