Hello
For each month there is a regression model that run and produce score (Y).
I would like to display the data set via proc report and apply a rule ad
S following:
If there is increase from one month to next month then color it in red.
If there is decrease from one month to next month then color it in green.
The calculation should be done for each row separately.
(Please note that green mean better explentaory variable or better resulted score)
(Please note that red mean worse explentaory variable or worse resulted score)
The colors will help the user (who look at the report) to understand if the customer had improvement or deterioration from one month to next month.
Please note that number of columns with nameYYMM can be different .
so i am looking for dynamic code that will work with any mumber of columns.
Data Have;
Input VAR_name $ Mon2301 Mon2302 Mon2303 Mon2304 Mon2305;
cards;
X1 70 70 70 70 70
X2 70 70 90 90 90
X3 40 40 40 40 40
X4 30 30 50 50 20
X5 70 45 45 45 45
X6 30 30 30 20 40
TOTAL 310 285 325 315 305
Y 7 6 9 9 7
;
Run;
Data Have;
Input VAR_name $ Mon2301 Mon2302 Mon2303 Mon2304 Mon2305;
cards;
X1 70 70 70 70 70
X2 70 70 90 90 90
X3 40 40 40 40 40
X4 30 30 50 50 20
X5 70 45 45 45 45
X6 30 30 30 20 40
TOTAL 310 285 325 315 305
Y 7 6 9 9 7
;
Run;
proc transpose data=have(obs=0) out=vname;
var _all_;
run;
data _null_;
set vname(firstobs=2) end=last;
length list $ 2000;
retain list;
list=catx(' ',list,_name_);
if last then do;
call symputx('list',list);
call symputx('last',_name_);
end;
run;
ods excel file='c:\temp\want.xlsx';
proc report data=have nowd;
define _all_/display;
compute &last.;
array x{*} &list. ;
do i=2 to dim(x);
if x{i}>x{i-1} then call define(vname(x{i}),'style','style={background=red}');
if x{i}<x{i-1} then call define(vname(x{i}),'style','style={background=green}');
end;
endcomp;
run;
ods excel close;
Thanks,
Can you please explain:
The calculation is done on all columns except of the first column .
You wrote compute only on the last column.
How SAS know to perform computation on all columns (Except first)While you type computation only on last column?
compute &last.;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.