BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

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

RichardADeVenezia_0-1605269883632.png

 

 

 

View solution in original post

5 REPLIES 5
Ksharp
Super User
Print it one by one .

proc report data=cars_unit;
where Origin='USA';
columns Make Horsepower, (mean std);
define make / group;
define Horsepower / "Horsepower [hp]" analysis;
run;

proc report data=cars_unit;
where Origin='EURO';
columns Make Horsepower, (mean std);
define make / group;
define Horsepower / "Horsepower [kW]" analysis;
run;
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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?

Ksharp
Super User

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.

RichardDeVen
Barite | Level 11

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

RichardADeVenezia_0-1605269883632.png

 

 

 

js5
Pyrite | Level 9 js5
Pyrite | Level 9
This is exactly what I was looking for, thanks!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 2057 views
  • 3 likes
  • 3 in conversation