- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-25-2019 08:30 AM
(3401 views)
I am looking to skip block of code based on some condition. Like if user does not enter date in the parameter of macro the following code won't run.
%macro test(final_File,date); /*Other macro*/ /****I want to skip the following Code if user doesn't enter date in parameter*****/ insert into &final_File._checkpoints set Checkpoints="Min Date", Total_Count=(select Count(&date.) from &final_File.), Date_Check=(select min(&date.) format date9. as min_date from &final_File.), comment="Min date of record", Update_Date=today(); run; /*Other macro*/ %mend;
same as we had in VBA,
If date="" then goto xx: Block of code which will be missed if condition matches here xx: run another code
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Depending on what is needed I would probably use %if - %then - %else block
And in the first %if evaluate your inputs for validity.
Example from the link below
/* capture conditional logic in macro */
%macro SummarizeIfExists();
%if %sysfunc(exist(work.result)) %then
%do;
proc means data=work.result;
run;
%end;
%else
%do;
%PUT WARNING: Missing WORK.RESULT - report process skipped.;
%end;
%mend;
/* call the macro */
%SummarizeIfExists();
Really broken down here:
https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are a few ways to check for a non-null value in a macro variable. The one I like is:
%if %length(&date) > 0 %then %do;
You could insert that in the middle of your macro (with a matching %end statement at the end of the conditional code).