BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Newbie to SAS here!

I was following this thread about adding an image to a report:
http://support.sas.com/forums/thread.jspa?messageID=5092Ꮴ

In particular I was following this example:
proc report data=example missing nowindows;
title 'another way';
column third second,( analisys number);
define third / group '^S={preimage="c:\temp\kermit.jpg"}^nthird';
define second / display across 'second';
define analisys /analysis ' ' ;
define number / analysis ' ';
rbreak after / summarize;
run;

I wanted to modify this example to show images for each row of my report. I was able to show the same image for each row using the example above. So that was good. Now I want to show the correct image for the correct ID. So I created a data step to create a column that contains the correct URL. However when I replace preimage with the column name, I don't get the image. Is there a way to do this?
Example (myimage is the column name):
define third / group {preimage=myimage}^nthird;

TIA
Patrick
8 REPLIES 8
Cynthia_sas
SAS Super FREQ
Hi:
I am not on my computer right now, so I don't have access to SAS or to my library of sample programs; however, what you want to do can be accomplished with CALL DEFINE. Look in the support.sas.com FAQ for information on CALL DEFINE. In addition, the PROC REPORT documentation has an example of using the URL argument for CALL DEFINE.

In short, what you have to do will be something like this

compute third;
call define(_COL_,'URL','code to set URL');
endcomp;

OR

compute third;
myurl= call define(_COL_,'URL','myurl');
endcomp;

Tech Support can help you figure out the exact syntax you need.
Good luck!
cynthia
deleted_user
Not applicable
Thanks. I have now got a link that will point to the image, however, I was hoping to get the image instead. Is there a way to do this?
Thanks again.
Olivier
Pyrite | Level 9
Hi.
You could define a format to associate image paths with data values. The format names are allowed in style specifications, whereas variable names aren't.
For example (with no proc Report because of my already related allergy ; proc Print instead words alright) :

PROC FORMAT ;
VALUE $seximg
"F" = "c:\temp\female.gif"
"M" = "c:\temp\male.gif"
;
RUN ;
ODS < whatever > ;
PROC PRINT DATA = sashelp.class NOOBS LABEL ;
VAR name ;
VAR sex / STYLE = [PREIMAGE=$seximg.] ;
VAR age height weight ;
RUN ;
ODS < whatever > CLOSE ;

Regards.
Olivier
Cynthia_sas
SAS Super FREQ
Hi...
And the PROC REPORT (to which you have an allergy) would also work with the format approach:

DEFINE SEX / DISPLAY
STYLE(COLUMN)={preimage=$seximg.};

the only warning is that the format value may have to change depending on what your ultimate destination may be:

HTML -- location where image will be located WHEN HTML page is LOADED (possibly a location on a web server machine):
PROC FORMAT ;
VALUE $seximg
"F" = "http://webserver/dir/female.gif"
"M" = "http://webserver/dir/male.gif";
RUN ;

PDF/RTF -- location where image will be located WHEN output file is CREATED:
PROC FORMAT ;
VALUE $seximg
"F" = "c:\temp\female.gif"
"M" = "c:\temp\male.gif";
RUN ;

;-)
cynthia
deleted_user
Not applicable
Thanks Olivier and Cynthia. But I don't think I was clear. I was able to see exactly what you both suggested. However in both examples these are static links. I want to change the image per id. When I used Cynthia's last example, I was able to get the link but not the actual image.

Here's my code below. In proc Report section, if I hardcode a static link, I will get an image (or lack thereof). However if I switch the hardcode value with one from my column, I do not get an image. The next section with Define mwimage2 does get me the clickable URL, but I would like to see the image:

proc sql;
CREATE TABLE SASUSER.DETAILLEVEL_REPORT_DAILY AS SELECT DETAILLEVEL_REPORT_DAILY.pageid FORMAT=11.,
DETAILLEVEL_REPORT_DAILY.dept,
DETAILLEVEL_REPORT_DAILY.lw_net_dollar,
DETAILLEVEL_REPORT_DAILY.lw_ly_net_demand_dollar,
DETAILLEVEL_REPORT_DAILY.oz_description FORMAT=$254.,
("http://slimages.macys.com/is/image/MCY/products/5/optimized/" || compress(put(DETAILLEVEL_REPORT_DAILY.pageid,w.) || "_fpx.tif")) FORMAT=$255. AS mwimage,
DETAILLEVEL_REPORT_DAILY.oz_description FORMAT=$254.,
("http://oz/merchreports/utility/getimagedata.php?id=" || compress(put(DETAILLEVEL_REPORT_DAILY.pageid,w.)) || "&divid=17") FORMAT=$255. AS mwimage2


FROM MYDATA.DETAILLEVEL_REPORT_DAILY AS DETAILLEVEL_REPORT_DAILY;
quit;

Proc report data =SASUSER.DETAILLEVEL_REPORT_DAILY;
/* Columns */
COLUMN Dept PageID oz_Description lw_net_dollar lw_ly_net_demand_dollar mwimage mwimage2;

/* Sort */
DEFINE Dept / ORDER;
Define PageID / Order;
/*Group bys */
Define Dept/ Group;
Define Pageid / Group "Product";
Define mwimage / Group "Image" style(column)={preimage='http://slimages.macys.com/is/image/MCY/products/5/optimized/94461_fpx.tif'};

Define mwimage2 / Group "Image2" ;
compute mwimage2;
call define(_COL_,'URL',mwimage2);
endcomp;

Define oz_Description /Group 'Description';

Define lw_net_dollar /Analysis format=Dollar15.2 'Demand/Sales';
Define lw_ly_net_demand_dollar /Analysis format=Dollar15.2 'Demand/LYSales';



/* Breaks/Summary */
Break AFTER Dept /Summarize OL SKIP;
RBreak AFTER /Summarize OL;
title "test Report";
quit;

Thanks again
Patrick
Cynthia_sas
SAS Super FREQ
Hi:
I am at SAS Global Forum and not on my machine right now. It looks to me like MWIMAGE is a dynamically generated HTTP reference for a TIF file and MWIMAGE2 is a dynamicallly generated URL that is meant to execute a PHP file.

Remember that when you GROUP on MWIMAGE and MWIMAGE2, that only the first occurence of the group will have a value -- the other rows for that group will have a blank value for MWIMAGE and/or MWIMAGE2.

Your best bet for a quick resolution is to contact Tech Support. They can help you figure out the best way to do what you want. Even though my example was a static URL, by the time your PROC SQL is finished, your column values are essentially static URLs. If I have a chance after SAS Global Forum, I'll try to work up a dynamic example with PROC REPORT. If you need help quickly, however, Tech Support can help you in a more timely fashion.

cynthia
Olivier
Pyrite | Level 9
Hi Patrick.

Since PAGEID seems to be numeric, the Format solution we both proposed with Cynthia still holds ; just consider using a Picture rather than a static format :

PROC FORMAT ;
PICTURE myImage
LOW-HIGH = "0000009_fpx.tif"
(PREFIX = "http://slimages.macys.com/is/image/MCY/products/5/optimized/")
;
RUN ;

Then use myImage. as the value for the PREIMAGE style attribute, when displaying PAGEID.

Cheers.
Olivier
deleted_user
Not applicable
Sorry for the delay on answering this. This was something I wanted to play with and then real life came back and I had to actually work.
I got to work with help of my trusty SAS consultant!
What we had to do was make a format using the pageid, and mwimage2 field. We
wrapped the mwimage2 field in an HTML image tag. We then used that format against the Pageid in the report

/* Start Format section */
proc sql;
create table work.oz_desc_image as
select distinct pageid as start, "" as label, 'imgfmt' as fmtname, 'n' as type
from
SASUSER.DETAILLEVEL_REPORT_DAILY;
quit;

proc format cntlin=work.oz_desc_image;
run;

/* End Format section */

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 798 views
  • 0 likes
  • 3 in conversation