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

 

Since ODS Excel doesn't support PREIMAGE and POSTIMAGE, I am looking for a simple way to implement image insertion within cell.

 

The paper below discusses solution in "UNIX operating environments via the Java object in the DATA step to post-process a worksheet to which you are adding an image." However, the example is only for Windows.

 

The ODS Excel Destination versus the ODS ExcelXP Tagset

 

Is there any simple way to insert image within a cell possibly without post-processing?

 

For example, insert image depending on Horsepower variable:

data temp; set sashelp.cars;
	if make="Audi";
	test=0;
run;

ods excel file= "&excel_export_path."  ;
	proc report data=temp nowd panels=2 SPLIT='{' spanrows;
	  	column ('Test' model Horsepower test);
		Compute test;
			 If Horsepower > 200 then  call define(_col_,"style","style=[preimage=Green.gif]");
			 Else if Horsepower < 200 then call define(_col_,'style',"style=[preimage=Red.gif]");
		endcomp;
	run; 
ods excel close;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Try inserting unicodes instead of the images. You may need to find the unicode values for the icons you want. 

 

ods escapechar='^';
proc report data=sashelp.class;
column Name Sex Symbol Age ;
define Symbol/computed;

compute Symbol/character length=50;
	if sex='M' then do;
		Symbol="^{unicode '2642'x}";
		call define(_col_,'style','style={color=red font_face="Arial Unicode MS" font_size=24pt}');
	end;
	else do;
		Symbol="^{unicode '2640'x}";
		call define(_col_,'style','style={color=green font_face="Arial Unicode MS" font_size=24pt}');
	end;
endcomp;
run;

Capture.PNG

If your interested, I searched here for unicodes.

Thanks,
Suryakiran

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

SAS have provided more functionality with ods excel/tagsets.excelxp, however I don't see it covering all the operation of a third party software anytime soon.  Do be aware that unless your setting the background image property of a cell, the image would generally be in a image box, hence not even part of the data. Afraid my advice is not going to change:

https://communities.sas.com/t5/ODS-and-Base-Reporting/Multiple-horizontal-reports-on-same-Excel-shee...

 

If you want to use specific Excel functionality, learn to create templates and use VBA code.

If you want to provide good interactive visualizations, use a visualization software - like spotfire, SAS VA, Tableua, PowerBI.

 

 

SuryaKiran
Meteorite | Level 14

Hello @KonstantinVasil,

 

What environment do you have, Unix/Linux or Windows?

 

Unfortunately, As of now ODS Excel can't insert images in cell level directly. If your on Windows environment, then you can try the %Excel_Enhance macro that was mentioned in paper Insights from a SAS Technical Support Guy:
A Deep Dive into the SAS® ODS Excel Destination.

 

Also check this blog for other ways to insert image in excel.

Thanks,
Suryakiran
Cynthia_sas
SAS Super FREQ
Also, the example you posted looks like it is using RED.GIF and GREEN.GIF to color a cell. There are other ways to do that particular type of traffic lighting without using images. What exactly is it that you want to do? Traffic light with colors? or insert a picture?
Cynthia
KonstantinVasil
Obsidian | Level 7

The environment is Unix/Linux - as I mentioned in the referenced link there is only example for Windows

 

The pictures which I am using aren't only colors but tick and cross traffic light signs - in fact, they are the same that Excel has as Icon Set for conditional formatting:

 

Conditional%2BFormatting%2B1

 

SuryaKiran
Meteorite | Level 14

Try inserting unicodes instead of the images. You may need to find the unicode values for the icons you want. 

 

ods escapechar='^';
proc report data=sashelp.class;
column Name Sex Symbol Age ;
define Symbol/computed;

compute Symbol/character length=50;
	if sex='M' then do;
		Symbol="^{unicode '2642'x}";
		call define(_col_,'style','style={color=red font_face="Arial Unicode MS" font_size=24pt}');
	end;
	else do;
		Symbol="^{unicode '2640'x}";
		call define(_col_,'style','style={color=green font_face="Arial Unicode MS" font_size=24pt}');
	end;
endcomp;
run;

Capture.PNG

If your interested, I searched here for unicodes.

Thanks,
Suryakiran
KonstantinVasil
Obsidian | Level 7

 

Thank you. The unicode work-around is clever although that the symbols are not exactly the same.

 

However, I run into some problems when the variable to which I am comparing is numeric. For example, the code below does not work unless Weight is defined as group or order. In my case, this is not a solution, because I have other group variables with spanrows and I do not want Weight to be spanned. Is there some way to assign Symbol based on a numeric variable that is not order or group variable?

 

ods escapechar='^';
proc report data=sashelp.class;
	column Name Sex Weight Symbol Age ;
	define Symbol/computed;
	/*define Weight/group;*/
	compute Symbol/character length=50;
		if Weight>100 then do;
			Symbol="^{unicode '2642'x}";
			call define(_col_,'style','style={color=red font_face="Arial Unicode MS" font_size=24pt}');
		end;
		else do;
			Symbol="^{unicode '2640'x}";
			call define(_col_,'style','style={color=green font_face="Arial Unicode MS" font_size=24pt}');
		end;
	endcomp;
run;
Cynthia_sas
SAS Super FREQ
Hi, if you want WEIGHT to be an analysis variable, with a default statistic of SUM, then the correct reference in the COMPUTE block would be
if weight.sum > 100

This is a compound name that PROC REPORT requires when your numeric variables are used as analysis variables on the report. Otherwise, if you are not calculating report breaks (grand totals) or group breaks (subtotals), then you can change the usage of WEIGHT to display and then you can use the simple
if weight>100
in your COMPUTE block.
Cynthia

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 7 replies
  • 4073 views
  • 7 likes
  • 4 in conversation