Download presentation
Presentation is loading. Please wait.
1
3 Parameter Validation
2
Perform parameter validation with the OR operator
Perform parameter validation with the OR operator. Perform parameter validation with the IN operator. Perform data-driven parameter validation. Perform parameter validation with the %INDEX function.
3
Example: Validate a parameter value before generating SAS code that is based on that value.
%macro customers(place); %let place=%upcase(&place); %if &place=AU or &place=CA or &place=DE or &place=IL or &place=TR or &place=US or &place=ZA %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %put Sorry, no customers from &place..; %mend customers; %customers(de) %customers(aa)
4
Example: Use the IN operator for parameter validation.
%macro customers(place) / minoperator; %let place=%upcase(&place); %if &place in AU CA DE IL TR US ZA %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %put Sorry, no customers from &place..; %mend customers; %customers(de) %customers(aa) The MINOPERATOR option is required.
5
%macro customers(place) / minoperator; %let place=%upcase(&place);
proc sql noprint; select distinct country into :list separated by ' ' from orion.customer; quit; %if &place in &list %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %do; %put Sorry, no customers from &place..; %put Valid countries are: &list..; %mend customers; %customers(de) %customers(aa) proc sql noprint; select distinct country into :list separated by ' ' from orion.customer; quit;
6
The %INDEX Function Use the %INDEX function to check the value of a macro variable against a list of valid values. General form of the %INDEX function: The %INDEX function does the following: searches argument1 for the first occurrence of argument2 returns an integer representing the position in argument1 of the first character of argument2 if there is an exact match returns 0 if there is no match %INDEX(argument1, argument2) The example which follows parallels the previous example, but uses %INDEX to mimic the macro IN operator. This would be of interest to folks who have not upgraded to SAS 9.2, the release in which the macro IN operator became permanently available.
7
The %INDEX Function %INDEX(argument1, argument2) argument1 and argument2 can be the following: constant text macro variable references macro functions macro calls
8
Example: Use the %INDEX function for parameter validation.
%macro customers(place); %let place=%upcase(&place); proc sql noprint; select distinct country into :list separated by '*' from orion.customer; quit; %if %index(*&list*,*&place*) > 0 %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %do; %put Sorry, no customers from &place..; %put Valid countries are: &list..; %mend customers; Note the use of asterisks.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.