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

Hi! I'm relatively new in SAS and now I'd like to create my own style of summary tables. For example, let's imagine data set which will be updated every day automatically (using date >= date()-10 or smth like this):

 

data last_decade_data;
input country date some_cost some_metric;
datalines;
USA 15OCT2018 500 0.1

USA16OCT2018 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;

 

Metric shouldn't be exactly inversely proportional to my cash flow, this is for example. Also it can be more than one country. All what I want is to summarize my data in this way (using proc sql/report/tabulate or using macro - doesn't matter, I will accept any solution):

 

country   sum(some_cost)    avg(some_metric)

  USA              5694                       0.108182

 

So the thing I desire is as follows:

 

country   sum(some_cost)    avg(some_metric)

  USA              5694                       0.108182

 

More specifically: I'd like to add an arrow (green up or red down depending on yesterday value, so maybe I should consider two such tables, I'm not sure) before the number in my table created by some method. I would like to do it using gifs for them that I have and loaded in sas (maybe I did it wrong) and by writing own proc format, but maybe there is another way or maybe someone could show me correct implementation of this way. I hope this thing already exists, so sources with any analogues will be also okay.

 

Here is an example of that I wnat approximately:

https://www.finam.ru/quotes/indices/ 

 

Any help or useful information will be kindly appreciated!:)

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Find out the unicode values for the arrows you want to use (there are different kinds) and then create a column concatenating the unicode and the value you want.

 

Something like this:

 

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 found the unicode values here

Thanks,
Suryakiran

View solution in original post

8 REPLIES 8
SuryaKiran
Meteorite | Level 14

Find out the unicode values for the arrows you want to use (there are different kinds) and then create a column concatenating the unicode and the value you want.

 

Something like this:

 

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 found the unicode values here

Thanks,
Suryakiran
esko1779
Fluorite | Level 6

Thanks for the fast reply!

 

I've tried your solution, but something went wrong and I couldn't see arrows in out table. I will try to fix it tomorrow and mention it here as well. But the question about built-in gifs in order to make more complex things remains still open. By the way, can I use CATS function in order to write smth like 5964 (-10%), where fontsize of '(-10%)' would be smaller than standard size of '5964'?

SuryaKiran
Meteorite | Level 14

Not sure what gifs your trying to create. 

Yes, you can control the style individually like adding something like 

CATS("~S={foreground=Green}~{unicode '2b06'x}~S={}",a.sum,"~S={fontsize=6pt}(-10%)") 

Note: You won't see the arrows in the table, you need to print that table inorder to see arrows (proc print or proc report)

image.png

Thanks,
Suryakiran
esko1779
Fluorite | Level 6

Thank you again, your method really works, but I have some problems with these symbols ('2b06' and '2b07'). My SAS is only able to display characters with less bytes (like '2191' and '2193'). Is there a way to fix it?

 

UPD: It can't be displayed in SAS panel even in proc report or proc print, but it is displayed nice in html file that I send to myself via Outlook (using ods html; ... ods html close; ).

ballardw
Super User

@esko1779 wrote:

Hi! I'm relatively new in SAS and now I'd like to create my own style of summary tables. For example, let's imagine data set which will be updated every day automatically (using date >= date()-10 or smth like this):

 

data last_decade_data;
input country date some_cost some_metric;
datalines;
USA 15OCT2018 500 0.1

USA16OCT2018 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;

 

Metric shouldn't be exactly inversely proportional to my cash flow, this is for example. Also it can be more than one country. All what I want is to summarize my data in this way (using proc sql/report/tabulate or using macro - doesn't matter, I will accept any solution):

 

country   sum(some_cost)    avg(some_metric)

  USA              5694                       0.108182

 

So the thing I desire is as follows:

 

country   sum(some_cost)    avg(some_metric)

  USA              5694                       0.108182

 

More specifically: I'd like to add an arrow (green up or red down depending on yesterday value, so maybe I should consider two such tables, I'm not sure) before the number in my table created by some method. I would like to do it using gifs for them that I have and loaded in sas (maybe I did it wrong) and by writing own proc format, but maybe there is another way or maybe someone could show me correct implementation of this way. I hope this thing already exists, so sources with any analogues will be also okay.

 

Here is an example of that I wnat approximately:

https://www.finam.ru/quotes/indices/ 

 

Any help or useful information will be kindly appreciated!:)

 


This may get you started

proc format library=work;
picture somevalue
low -<0 ='000009.999' (prefix='(*ESC*){unicode "2193"x}')
0<-high ='000009.999' (prefix='(*ESC*){unicode "2191"x}')
;
run;

data junk;
  do x= -22.35, 0, 123.45;
   output;
  end;
run;
proc print data=junk;
   var x;
   format x somevalue.;
run;

With a PICTURE format it is going to be up to you to determine the appropriate number of desired digit selectors and such.

 

 

I tried a quick attempt creating color generically with (*ESC*){style [color=red]} but that try didn't assign color to the character. The (*ESC*) functions in a format similar to the ESCAPECHAR character and should work with many of the

esko1779
Fluorite | Level 6

Thanks for reply! But sorry, my SAS can't display the output of your code. It's asking me to use html format instead of yours (or instead or some other format, I'm not sure). 

ballardw
Super User

@esko1779 wrote:

Thanks for reply! But sorry, my SAS can't display the output of your code. It's asking me to use html format instead of yours (or instead or some other format, I'm not sure). 


Which operating system and version of SAS are you running?


I believe unless you are running on a mainframe that ODS HTML is the default for the results window and would have to be turned off by someone.

 

You should be able to generate html output by

 

ods html;

<any procedure generating output>

 

ODS RTF and PDF files should also work.

esko1779
Fluorite | Level 6

Got it, thanks! Gonna test your code soon.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3208 views
  • 5 likes
  • 3 in conversation