Sample 43243: How to pass in multiple values for a single parameter and then parse out each value
This sample is similar to the sample for PARMBUFF that is in the documentation, but it is easier to understand and is more dynamic. It can handle special characters being passed in as part of the parameter. This code is valid starting in SAS8®.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This code uses PARMBUFF and &SYSPBUFF to pass in multiple parameters to a macro. The COUNTW function is then used to count the number of values passsed into the parameter. Finally, the %SCAN function pulls off each value from the parameter.
This example passes in three data set names as the value of the macro parameter. Each data set name is returned by the %SCAN function and is then used to list the data set name to be used by PROC PRINT.
options mprint;
/*sample data*/
data work.one;
input x1 x2 x3;
datalines;
1 2 3
;
data work.two;
input x1 x2 x3;
datalines;
4 5 6
;
data work.three;
input x1 x2 x3;
datalines;
7 8 9
;
%macro test/parmbuff;
/*counts the number of data sets passed in as the parameter*/
%let n=%sysfunc(countw(&syspbuff,%str(,)));
/*loops through each data set*/
%do i=1 %to &n;
/*pulls off each data set*/
%let dsn=%scan(%qsysfunc(compress(%bquote(&syspbuff),%str(%(%)))),&i,%str(,));
/*proc prints each data set*/
proc print data=&dsn;
run;
%end;
%mend;
/*pass in the data sets you want to work with. Make sure the names are comma delimited*/
%test(work.one,work.two,work.three)
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The SAS System
Obs x1 x2 x3
1 1 2 3
The SAS System
Obs x1 x2 x3
1 4 5 6
The SAS System
Obs x1 x2 x3
1 7 8 9
This example is very similar to the example for PARMBUFF, but this method is easier to understand and is more dynamic. This code is valid starting in SAS8®.
Date Modified: | 2011-05-16 13:49:38 |
Date Created: | 2011-05-11 16:26:25 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.21 | | 9.2 TS2M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows XP 64-bit Edition | 9.21 | | 9.2 TS2M0 | |
Microsoft® Windows® for x64 | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 for x64 | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows Server 2008 for x64 | 9.21 | | 9.2 TS2M0 | |
Microsoft Windows XP Professional | 9.21 | | 9.2 TS2M0 | |
Windows Vista | 9.21 | | 9.2 TS2M0 | |
Windows Vista for x64 | 9.21 | | 9.2 TS2M0 | |
64-bit Enabled AIX | 9.21 | | 9.2 TS2M0 | |
64-bit Enabled HP-UX | 9.21 | | 9.2 TS2M0 | |
64-bit Enabled Solaris | 9.21 | | 9.2 TS2M0 | |
HP-UX IPF | 9.21 | | 9.2 TS2M0 | |
Linux | 9.21 | | 9.2 TS2M0 | |
Linux for x64 | 9.21 | | 9.2 TS2M0 | |
OpenVMS on HP Integrity | 9.21 | | 9.2 TS2M0 | |
Solaris for x64 | 9.21 | | 9.2 TS2M0 | |