The pseudo code below will demonstrate what I would like to do.
Assume I have a macro of the sort:
%MyMacro(Part1YesOrNO, Part2YesOrNO);
Some code representing "Part 1";
.
.
.
Some code representing "Part 2";
%mend MyMacro;
Now, if the user types in:
%MyMacro(Yes, Yes);
both parts of the Macro should be run.
If the user types in:
%MyMacro(Yes, No);
Only part 1 of the Macro should be run.
Any advice of how I could achieve this kind of functionality?
%MyMacro(Part1YesOrNO, Part2YesOrNO);
%if %upcase(&part1yesorno)=YES %then %do;
Some code representing "Part 1";
%end;
.
%if %upcase(&part2yesorno)=YES %then %do; .
Some code representing "Part 2";
%end;
%mend MyMacro;
Hint: don't use such long variable names unless they are absolutely necessary, I would create the macro as follows
%macro mymacro(part1,part2);
unless you are a much better typist than I am, I find shorter name that still have meaning a much better approach, its less typing and less chance for error. Also, I prefer values of Y or N to Yes or No, again simplicity and less typing and less chance for error.
%macro mymacro(part1yesorno, part2yesorno);
%if %upcase(%substr(&part1yesorno, 1, 1)) = Y %then %do;
/* your part1 code goes here */
%end;
%if %upcase(%substr(&part2yesorno, 1, 1) = Y %then %do;
/* your part2 code goes here */
%end;
%mend;
%mymacro(Yes, No);
%MyMacro(Part1YesOrNO, Part2YesOrNO);
%if %upcase(&part1yesorno)=YES %then %do;
Some code representing "Part 1";
%end;
.
%if %upcase(&part2yesorno)=YES %then %do; .
Some code representing "Part 2";
%end;
%mend MyMacro;
Hint: don't use such long variable names unless they are absolutely necessary, I would create the macro as follows
%macro mymacro(part1,part2);
unless you are a much better typist than I am, I find shorter name that still have meaning a much better approach, its less typing and less chance for error. Also, I prefer values of Y or N to Yes or No, again simplicity and less typing and less chance for error.
Consider:
%MyMacro(Part1YesOrNO, Part2YesOrNO);
%if &part1yesorno=Yes %then %do;
*Some code representing "Part 1";
%end;
%if &part2yesorno=Yes %then %do;
*Some code representing "Part 2";
%end;
%mend MyMacro;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.