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
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/
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).
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.