- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 =
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%if %length(¶m1.) %then and (¶m1.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%if %length(¶m1.) %then and (¶m1.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation