BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
snip
Obsidian | Level 7

I'm on a proc report, and I want to compare two analysis variables:

var2 and var1.

if var2>var1 ==> green arrow||value(var2) (concatenation)

if var2<var1 ==> red arrow||value(var2) (concatenation)

data last_decade_data;
input country:$8. date:Date9. some_cost some_metric;
format date date9.;
datalines;
USA 15OCT2018 500 0.1
USA 16OCT2018 501 0.09
USA 17OCT2018 504 0.08
USA 18OCT2018 480 0.2
USA 19OCT2018 550 0.06
USA 20OCT2018 515 0.07
USA 21OCT2018 552 0.05
USA 22OCT2018 593 0.04
USA 23OCT2018 499 0.3
USA 24OCT2018 500 0.1
USA 25OCT2018 500 0.1
;
run;

proc sql;
create table test as 
select a.country,case when a.sum>b.pre_sum then CATS("~S={foreground=Green}~{unicode '2b06'x}~S={}",a.sum) 
									 else CATS("~S={foreground=red}~{unicode '2b07'x}~S={}",a.sum) end as Sum,
		   case when a.avg>pre_avg then   CATS("~S={foreground=Green}~{unicode '2b06'x}~S={}",a.avg) 
									 else CATS("~S={foreground=red}~{unicode '2b07'x}~S={}",a.avg) end as Avg
	from (select Country,sum(some_cost) as sum,avg(some_metric) as avg
			from last_decade_data 
			group by country) as a
left join (select Country,sum(some_cost) as pre_sum,avg(some_metric) as pre_avg
				from last_decade_data
				where date<today()
				group by country) as b
	on a.country=b.country
;
quit;
ods escapechar='~';
proc print data=test noobs;
run;

/*{unicode '2b06'x} for ArrowDown*/
/*{inocode '2bo7'x} for ArrowUp*/

I want to display the arrows in var2 next to the values.

I found this code but I can't adapt it to a proc report if you can help me please.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

How about showing code for the report without the arrows and then indicate just where the arrows are supposed to appear.

View solution in original post

3 REPLIES 3
ballardw
Super User

How about showing code for the report without the arrows and then indicate just where the arrows are supposed to appear.

Ksharp
Super User
data have;
input var1 var2;
x=unicode("\u2b07");
cards;
1 2
2 4
4 2
2 1
;

ods escapechar='~';
proc report data=have nowd;
columns var1 var2 want;
define var1/display;
define var2/display;
define want/computed;
compute want/character length=100;
 if var2>var1 then want=cat("~{style [foreground=green fontsize=8] ~{unicode '2b07'x}}",var2);
  else if var2<var1 then want=cats("~{style [foreground=red fontsize=8] ~{unicode '2b06'x}}",var2);
    else want=cats(var2);
endcomp;
run;

 

Ksharp_0-1696043948219.png

 

snip
Obsidian | Level 7

Thank's  👍

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!
How to Concatenate Values

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.

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
  • 3 replies
  • 485 views
  • 2 likes
  • 3 in conversation