Help using Base SAS procedures

variable name and array

Occasional Contributor
Posts: 9

variable name and array


I am working with sas arrays I want to output a value and variable name and value in one column that has a value greater than say 10.

I am running sas code similar to this :

data temp; set temp2;

array abs{*} _numeric_;

do i = 1 to dim(abs);
if(abs(i) > 10) then variable_gr10 = x1|| ... here i want to append name of the variable


Is there any way I could simply get name of the particular variable and append it with another value in the data ?

Posts: 8,743

Re: variable name and array

Just wondering...

are you seeing any warning messages in the SAS log. ABS is the name of a SAS function.
doc for ABS function:


It says in the doc:

Using the name of a SAS function as an array name can cause unpredictable results.

If you inadvertently use a function name as the name of the array, SAS treats parenthetical references that involve the name as array references, not function references, for the duration of the DATA step. A warning message is written to the SAS log.

As for your question about creating a new character variable, then this code shows how to use the VNAME function to grab the variable name of an array member.

7714 data makearr;
7715 length newcharvar $15;
7716 set sashelp.class(obs=2);
7717 array allnum _numeric_;
7718 do i = 1 to dim(allnum);
7719 varname = vname(allnum(i));
7720 newcharvar = cats('_',put(_n_,2.0),'_',put(i,2.0),'_xxx_',trim(varname));
7721 putlog _n_= i= name= varname= newcharvar=;
7722 end;
7724 run;

_N_=1 i=1 Name=Alfred varname=Age newcharvar=_1_1_xxx_Age
_N_=1 i=2 Name=Alfred varname=Height newcharvar=_1_2_xxx_Height
_N_=1 i=3 Name=Alfred varname=Weight newcharvar=_1_3_xxx_Weight
_N_=2 i=1 Name=Alice varname=Age newcharvar=_2_1_xxx_Age
_N_=2 i=2 Name=Alice varname=Height newcharvar=_2_2_xxx_Height
_N_=2 i=3 Name=Alice varname=Weight newcharvar=_2_3_xxx_Weight
NOTE: There were 2 observations read from the data set SASHELP.CLASS.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation