Can someone please help me quote / mask the below so that it works with all options.
Basically, I want to allow the use to filter the dataset using any SAS condition, so they could enter double quotes, single quotes, OR, = etc.
Is there any way where there is no need to mask while calling the macro?
data testdata;
length account_status $20 marker $10 prod_type 8;
account_status="Current"; prod_type = 1; marker=''; output;
account_status="30days"; prod_type = 2; marker=''; output;
account_status="60days"; prod_type = 2; marker=''; output;
account_status="90days"; prod_type = 3; marker=''; output;
run;
%MACRO mymacro(param1= );
data accounts_data ;
set testdata (where = (MISSING(marker)
%if "¶m1." NE "" %then %do;
AND (¶m1.)
%end;
));
run;
%MEND mymacro;
/* P1 PD Stability Volume - Volume By PD Pillar 1 Bands (Scored Segments Only) */
%mymacro(param1 = (account_status ^= "Current" and prod_type ^= 1)
);
%mymacro(param1 = (prod_type ^= 1)
);
%mymacro(param1 =
);
What for? If they can write conditions, they can do the rest of the code anyway.
Creating and maintaining such a macro (and the making of the calls) will be more effort than you could possibly save by using it.
Initially to get this working.
Secondly, these will be then used by the development team to validate the outputs, so they may filter as needed. So I need to bring this in a position where this is working and not many changes are required.
Hi @Sanjay_M ,
Read this article by Susan O'Conor: https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf
It will explain you everything.
All the best
Bart
You appear to be asking two questions. One is how to handle an optional parameter. Second how to make it easier to pass in complex strings.
In general I find that %LENGTH() is a good way to test if the parameter is set. You can "fool" it by use %STR( ) to send in a non-empty string that only contains blanks. If that is a concern look at this classic paper by Chung and King that tests many different ways of testing if a macro variable is "blank". https://support.sas.com/resources/papers/proceedings09/022-2009.pdf
For passing values for this problem you might be able to use SYSPBUFF.
But perhaps it is just easier to tell the users to add parentheses around the values. Extra parentheses will not hurt the logic of your generated WHERE clause. Although they could still break your earlier test for empty values by passing in parentheses with nothing between them.
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.