HI there,
I would like to do an action on a particular cell in Proc Report conditional on the value of other variables on that record.
Using the generic data below for example I would like weight to show red whenever married=1 or ed=2.
The "married condition" is partially working in that weight is highlighted red for the first record with married=1. However it doesnt work for the rest of the records and this seems to be down to the fact that married is an order variable and not repeating. I do require married to be an ordered variable so I wonder how I can make the compute block look at the actual value here.
Secondly the "ed" condition isn't working at all and I can see no reason why.
This is probably down to being relatively new to Proc Report but any help much appreciated!
data base;
set sashelp.bweight (obs=25);
run;
proc report data = base;
col married boy smoke weight ed;
define married / order;
define boy / order;
define smoke / order;
define weight / display;
define ed / display;
compute weight;
if married=1 then do;
call define(_col_,"style","style={background=red}");
end;
else if ed=2 then do;
call define(_col_,"style","style={background=red}");
end;
endcomp;
compute after married;
line ' ';
endcomp;
compute after boy;
line ' ';
endcomp;
run;
Hi
Since the value of an order variable is only available in the very first row, you need to put the value aside.
The followingcode sample illustrates the basic principle on how to do this.
proc report data=sashelp.class;
column age name sex _dummy;
define age / order;
define name / display;
define sex / display;
define _dummy / computed;
compute _dummy / char length=32;
if missing(age) = 0 then do;
saveAge = age;
end;
_dummy = cats("age=", age, ",saveAge=", saveAge);
endcomp;
compute after age;
line " ";
endcomp;
run;
I would recommend to add a "dummy" column add the very end to your report. In the compute block of this dummy variable, you have access to all the variables to left in your report.
The dummy varibale does not need to be printed, so simply add the NOPRINT option in the define statement.
Bruno
Hi
Since the value of an order variable is only available in the very first row, you need to put the value aside.
The followingcode sample illustrates the basic principle on how to do this.
proc report data=sashelp.class;
column age name sex _dummy;
define age / order;
define name / display;
define sex / display;
define _dummy / computed;
compute _dummy / char length=32;
if missing(age) = 0 then do;
saveAge = age;
end;
_dummy = cats("age=", age, ",saveAge=", saveAge);
endcomp;
compute after age;
line " ";
endcomp;
run;
I would recommend to add a "dummy" column add the very end to your report. In the compute block of this dummy variable, you have access to all the variables to left in your report.
The dummy varibale does not need to be printed, so simply add the NOPRINT option in the define statement.
Bruno
That works really welly. I also hadn't realized that the vars used in the compute block need to be to the left of the computed var. Cheers!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.