Sample 24798: Using CALL VNEXT to create a macro variable containing a list of variables in a DATA set
Use CALL VNEXT and CALL SYMPUT to create a macro
variable that resolves to a space-delimited list of the
data set's variables.
Note:
CALL VNEXT returns the name, type, and length of a
variable that is used in a DATA step, including
automatic variables. This sample only pulls the
variable name. Extra logic is used to exclude the
variables created in the current step and automatic
variables.
CALL VNEXT is new in SAS 9.0.
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.
data test;
a=1;
b=1;
c=1;
d=1;
e=1;
run;
data _null_;
set test;
length list $200 name $32;
do i=1 to 99 until(name=' ');
call vnext(name);
/* Omit automatic variables, and variables created in this step only */
if trim(name) not in('list','name','flag','i',' ','_ERROR_','_N_') then do;
if flag=0 then list=name;
else list=trim(list)||' '||name;
flag+1;
end;
call symput('varlist',list);
end;
run;
%put &varlist;
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.
OUTPUT to SAS log
a b c d e
Use CALL VNEXT and CALL SYMPUT to create a macro
variable that resolves to a space-delimited list of the
data set's variables.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> CALL routines
|
| Date Modified: | 2005-12-08 11:34:36 |
| Date Created: | 2004-09-30 14:09:15 |
Operating System and Release Information
| SAS System | Base SAS | Tru64 UNIX | 9 TS M0 | n/a |
| OpenVMS Alpha | 9 TS M0 | n/a |
| HP-UX IPF | 9 TS M0 | n/a |
| Linux | 9 TS M0 | n/a |
| 64-bit Enabled Solaris | 9 TS M0 | n/a |
| 64-bit Enabled HP-UX | 9 TS M0 | n/a |
| 64-bit Enabled AIX | 9 TS M0 | n/a |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | n/a |
| z/OS | 9 TS M0 | n/a |