Usage Note 32142: Processing multi-value input parameters in a stored process
It is sometimes necessary to process multi–value input parameters within a stored process. This sample illustrates a very basic example.
Consider the scenario that an input parameter named YEAR has been registered with a stored process that is executing on a SAS® Stored Process Server. Multiple year values can be selected by the user from a list, and only those selected years will be displayed in printed output from the SASHELP.RETAIL data set.
Because a SAS macro variable can only have one value, one or more macro variables will be created when the user selects the year values and submits the stored process. If only one YEAR is selected by the user, then only one macro variable, named &YEAR, will be passed over to the stored process. However, if more than one YEAR value is selected by the user, multiple macro variables will be created. A numeric suffix is added to the parameter name to distinguish between values. The number of values is set in the macro variable YEAR0, the first value is set in the macro variable YEAR1, and so on. For example:
YEAR=<first selected value>
YEAR0=<the total number of selected values>
YEAR1=<first selected value>
YEAR2=<second selected value>
YEAR3=<third selected value>
...etc...
Therefore, if the user selects the values 1990, 1991 and 1992 from the list of years in the client application, the following macro variables will be created:
YEAR=1990
YEAR0=3
YEAR1=1990
YEAR2=1991
YEAR3=1992
Example code to process multiple input values for YEAR
/* Define macro to create list of years selected by the user */
%macro yearlist;
%global year0;
/* If more than one year value was selected then cycle through the values */
%if %eval(&year0 ge 2) %then %do;
%do i=1 %to &year0;
&&year&i
%end;
%end;
/* If only one year value was selected */
%else &year
%mend yearlist;
/* Use the list of values in a WHERE statement */
%stpbegin;
proc print data=sashelp.retail;
where year in(%yearlist);
run;
%stpend;
Additional Documentation
Multiple ValuesOperating System and Release Information
| SAS System | SAS Integration Technologies | z/OS | 9.1 TS1M3 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 | |
| Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 | |
| Microsoft® Windows® for x64 | 9.1 TS1M3 | |
| Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 | |
| Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 | |
| Microsoft Windows 2000 Server | 9.1 TS1M3 | |
| Microsoft Windows 2000 Professional | 9.1 TS1M3 | |
| Microsoft Windows NT Workstation | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 | |
| Microsoft Windows XP Professional | 9.1 TS1M3 | |
| Windows Vista | 9.1 TS1M3 | |
| 64-bit Enabled AIX | 9.1 TS1M3 | |
| 64-bit Enabled HP-UX | 9.1 TS1M3 | |
| 64-bit Enabled Solaris | 9.1 TS1M3 | |
| HP-UX IPF | 9.1 TS1M3 | |
| Linux | 9.1 TS1M3 | |
| OpenVMS Alpha | 9.1 TS1M3 | |
| Solaris for x64 | 9.1 TS1M3 | |
| Tru64 UNIX | 9.1 TS1M3 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
| Type: | Usage Note |
| Priority: | |
| Topic: | Query and Reporting Common Programming Tasks ==> Conditional Processing Common Programming Tasks ==> Iterative Processing Common Programming Tasks
|
| Date Modified: | 2008-07-29 15:10:09 |
| Date Created: | 2008-05-16 17:02:30 |