Dear community,
I was wondering if there is a way of dynamically changing the label of proc report column label, using call define or otherwise? Please consider the below example:
data cars_unit;
set sashelp.cars;
length Unit $5;
if Origin EQ "Europe" then
Unit = "kW";
else Unit = "hp";
run;
proc sort data=cars_unit;
by Origin;
proc report data=cars_unit;
by Origin;
columns Make Horsepower, (mean std);
define make / group;
define Horsepower / "Horsepower [hp]" analysis;
run;
I would like to have the label say "Horsepower [kW]" if the Origin is Europe. I could probably to achieve the desired goal using macros but I was wondering if it can be done using proc report alone. Thank you.
You can not change the label dynamically.
Things that change dynamically will have to be data.
ACROSS is used to place data values in the column header area of the report.
Q: So what to change in data transformation ?
A: The unit
Instead of unit being only 'hp' or 'Kw', make it 'Power (hp)' or 'Power (kW)'
The 1:1 association you are forcing between origin and power unit allow you to use unit as ACROSS
Example:
data cars_unit; set sashelp.cars; length Unit $15; if Origin EQ "Europe" then do; Unit = "Power (kW)"; Power = horsepower / 1.34102209; end; else do; Unit = "Power (hp)"; Power = horsepower; end; keep origin make power unit; run; proc sort data=cars_unit; by Origin; ods html file='cars.html' style=plateau; proc report data=cars_unit; by Origin; columns Make unit,power,(mean std); define make / group; define unit / ' ' across; define Power / ' ' analysis; where make in: ('A','B','C','D','L'); run; ods html close;
Output image
This would work, but would not be that different to the macro solution I was hoping to avoid. So there is no way of solving this using compute/call define?
You may get it by LINE , but I am not sure that if style is what you want to see?
Or @Cynthia_sas maybe have a good idea.
You can not change the label dynamically.
Things that change dynamically will have to be data.
ACROSS is used to place data values in the column header area of the report.
Q: So what to change in data transformation ?
A: The unit
Instead of unit being only 'hp' or 'Kw', make it 'Power (hp)' or 'Power (kW)'
The 1:1 association you are forcing between origin and power unit allow you to use unit as ACROSS
Example:
data cars_unit; set sashelp.cars; length Unit $15; if Origin EQ "Europe" then do; Unit = "Power (kW)"; Power = horsepower / 1.34102209; end; else do; Unit = "Power (hp)"; Power = horsepower; end; keep origin make power unit; run; proc sort data=cars_unit; by Origin; ods html file='cars.html' style=plateau; proc report data=cars_unit; by Origin; columns Make unit,power,(mean std); define make / group; define unit / ' ' across; define Power / ' ' analysis; where make in: ('A','B','C','D','L'); run; ods html close;
Output image
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.