BookmarkSubscribeRSS Feed
rickw
Calcite | Level 5
Hi,

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
end;

run;

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

Thanks
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Just wondering...
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000201956.htm

are you seeing any warning messages in the SAS log. ABS is the name of a SAS function.
doc for ABS function:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000245861.htm

cynthia

It says in the doc:

CAUTION:
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.

[pre]
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;
7723
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.

[/pre]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 680 views
  • 0 likes
  • 2 in conversation