- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------