How Do I assign by-group images?
Imagine that for both by group values "Asia" and "Canada" I have 2 png's with the same naming?
data SHOES; set SASHELP.SHOES; run; proc sort data=shoes; by region product; run; ods graphics on; proc report data=shoes spanrows; where region in ('Asia' 'Canada') and product in ('Boot' 'Sandal' 'Slipper'); title 'Ex 1a) COMPUTE BEFORE/AFTER _PAGE_'; column region product sales returns Profit inventory PctInv ; define region / group; define product / group; define profit / computed f=dollar14.; define pctinv / computed f=percent9.2; break after region/summarize; rbreak after / summarize; compute pctinv; profit = sum(sales.sum,-1*returns.sum); pctinv = sales.sum / inventory.sum; endcomp; compute before _page_ / style={background=white just=left preimage='/caslibs/marketing/Asia.png?height=4cm&width=6cm'} ; /* should depend on byval */ line ' '; endcomp; run;
@BrunoMueller , any idea 🙂 ?
Hi:
That looks like code from my COMPUTE block paper. I do not think you'll be able to dynamically change the preimage file name without using SAS Macro processing. The PROC REPORT code needs to have that value resolved and the preimage value changed either based on a BY variable (which you don't have in your code) or with a Macro variable. You might be able to do it in the Report Writing Interface. I did mock up an example using a SAS macro program -- basically you have to call it one time for every "by" group and then one time for the final Grand Total that would come from the RBREAK:
I just used clip art for the image for Asia and Canada and then the macro program had only one macro parameter called &WANTREG. I don't have a CAS image to play on right now, so I just used my local install:
%macro makerep(wantreg=);
proc report data=shoes spanrows;
title1 j=c'Ex 1a) COMPUTE BEFORE/AFTER _PAGE_';
where region = "&wantreg";
column region product sales returns Profit inventory PctInv ;
define region / group;
define product / group;
define profit / computed f=dollar14.;
define pctinv / computed f=percent9.2;
break after region/summarize page;
compute pctinv;
profit = sum(sales.sum,-1*returns.sum);
pctinv = sales.sum / inventory.sum;
endcomp;
compute before _page_ / style={background=white just=left
preimage="c:\temp\&wantreg..png?height=4cm&width=6cm"};
line ' ' ;
endcomp;
run;
%mend makerep;
data SHOES;
set SASHELP.SHOES;
where region in ('Asia' 'Canada') and product in ('Boot' 'Sandal' 'Slipper');
run;
proc sort data=shoes;
by region product;
run;
ods pdf file='c:\temp\useimg.pdf';
%makerep(wantreg=Asia);
%makerep(wantreg=Canada);
** Grand Total;
proc report data=shoes spanrows;
column reg prod sales returns Profit inventory PctInv ;
define reg / computed 'Region';
define prod / computed 'Product';
define profit / computed f=dollar14.;
define pctinv / computed f=percent9.2;
compute reg / character length=11;
reg = 'All Regions';
endcomp;
compute prod / character length=15;
prod = 'All Products';
endcomp;
compute pctinv;
profit = sum(sales.sum,-1*returns.sum);
pctinv = sales.sum / inventory.sum;
endcomp;
run;
ods pdf close;
Cynthia
Hi:
That looks like code from my COMPUTE block paper. I do not think you'll be able to dynamically change the preimage file name without using SAS Macro processing. The PROC REPORT code needs to have that value resolved and the preimage value changed either based on a BY variable (which you don't have in your code) or with a Macro variable. You might be able to do it in the Report Writing Interface. I did mock up an example using a SAS macro program -- basically you have to call it one time for every "by" group and then one time for the final Grand Total that would come from the RBREAK:
I just used clip art for the image for Asia and Canada and then the macro program had only one macro parameter called &WANTREG. I don't have a CAS image to play on right now, so I just used my local install:
%macro makerep(wantreg=);
proc report data=shoes spanrows;
title1 j=c'Ex 1a) COMPUTE BEFORE/AFTER _PAGE_';
where region = "&wantreg";
column region product sales returns Profit inventory PctInv ;
define region / group;
define product / group;
define profit / computed f=dollar14.;
define pctinv / computed f=percent9.2;
break after region/summarize page;
compute pctinv;
profit = sum(sales.sum,-1*returns.sum);
pctinv = sales.sum / inventory.sum;
endcomp;
compute before _page_ / style={background=white just=left
preimage="c:\temp\&wantreg..png?height=4cm&width=6cm"};
line ' ' ;
endcomp;
run;
%mend makerep;
data SHOES;
set SASHELP.SHOES;
where region in ('Asia' 'Canada') and product in ('Boot' 'Sandal' 'Slipper');
run;
proc sort data=shoes;
by region product;
run;
ods pdf file='c:\temp\useimg.pdf';
%makerep(wantreg=Asia);
%makerep(wantreg=Canada);
** Grand Total;
proc report data=shoes spanrows;
column reg prod sales returns Profit inventory PctInv ;
define reg / computed 'Region';
define prod / computed 'Product';
define profit / computed f=dollar14.;
define pctinv / computed f=percent9.2;
compute reg / character length=11;
reg = 'All Regions';
endcomp;
compute prod / character length=15;
prod = 'All Products';
endcomp;
compute pctinv;
profit = sum(sales.sum,-1*returns.sum);
pctinv = sales.sum / inventory.sum;
endcomp;
run;
ods pdf close;
Cynthia
Thank you @Cynthia_sas
You're right, I was reading through your paper which was very helpful.
Actually I found a solution in http://de.saswiki.org/images/f/f7/18_KSFE_2014_Wern_-_PROC_REPORT_-_Decathlon.pdf
Here comes the code which is working for me.
ods graphics on;
options missing=' ';
proc report data=dna.all spanrows nowd style(report)=[rules=none frame=void linethickness=4 ];
where lowcase(brand) ne "other";
title 'KPI overview';
column logo brand producto ren fin kpi ;
define brand / group noprint;
define producto / group ;
define ren / sum;
define fin / sum;
define logo / computed ;
define kpi / computed f=percent9.1;
break before brand / summarize;
/* rbreak after / summarize; */
compute kpi;
kpi = ren.sum / fin.sum;
if strip(_break_) not in ("_RBREAK_" "" ) then CALL DEFINE('LOGO','STYLE',"STYLE=
{PREIMAGE='/caslibs/marketing/" ||TRIM(lowcase(brand))|| ".png?height=3cm'}");
endcomp;
run;.
Hi @Cynthia_sas
I've added a do loop functionality.
Now it works nice.
%macro makerep(wantreg=);
options missing=' ';
%do i=1 %to %sysfunc(countw(&wantreg,%str( )));
%let temp=%scan(&wantreg., %eval(&i));
proc report data=dna.all spanrows nowd style(report)=[rules=none frame=void linethickness=4 ];
where lowcase(brand) = %unquote(%str(%')&temp%str(%'));
title 'KPI overview';
column brand producto ren fin kpi ;
define brand / group noprint;
define producto / group ;
define ren / sum;
define fin / sum;
define kpi / computed f=percent9.1;
break before brand / summarize ;
compute kpi;
kpi = ren.sum / fin.sum;
endcomp;
compute before _page_ / style={background=white just=left
preimage="/caslibs/marketing/&temp..png?height=3cm"};
line ' ' ;
endcomp;
run;
%end;
%mend makerep;
options mlogic symbolgen;
%makerep(wantreg=vw audi skoda lcv);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.