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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 504 views
  • 0 likes
  • 3 in conversation