In this thread
Use of ARRAY in PROC REPORT COMPUTE block
@Ksharp shows how to use array statements in a compute block in PROC REPORT.
Can something similar be used if there is an ACROSS variable? For example, in this code, could I create an ARRAY in a COMPUTE block and then have it work on all three columns of the variable ORIGIN to turn some cells green or yellow in those 3 columns?
proc report data=sashelp.cars;
columns cylinders origin,mpg_city;
define cylinders/group;
define origin/across;
define mpg_city/mean;
run;
It is a matter of figuring out how PROC REPORT will name the variables.
proc report data=sashelp.cars out=test;
columns cylinders origin,mpg_city a;
define cylinders/group;
define origin/across;
define mpg_city/mean;
define a / computed;
compute a;
array _x _C2_ _C3_ _C4_;
a = sum(of _x[*]);
endcomp;
run;
Okay, thanks @data_null__ , that works!
proc report data=sashelp.cars out=test;
columns cylinders origin,mpg_city dummy;
define cylinders/group;
define origin/across;
define mpg_city/mean;
define dummy / computed noprint;
compute dummy;
array _x _C2_ _c3_ _C4_;
do i=1 to dim(_x);
if _x{i}>15 and _x{i}>0 then call define(vname(_x{i}),'style','style=[background=lightmoderategreen]');
else if _x{i}>0 then call define(vname(_x{i}),'style','style=[background=lightmoderatered]');
end;
endcomp;
run;
but now here's a related problem that I need to solve — suppose the across variable has 50 levels. Do I have to type all 50 _c2_ through _c51_ in the ARRAY statement, or is there an easier way to do this? I tried using
array _x _C2_--_C51_;
but that produces an error.
I realize I can use a macro here if I need to to create all 50 variable names, I'm hoping there's another way.
%macro colarray(s,n);
%local i;
%do i = &s %to &n;
_C&n._
%end;
%mend;
SAS-Variable lists don't work I reckon because the data loop part of PROC REPORT doesn't know those names.
Added start parameter.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.