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

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 🙂 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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:

Cynthia_sas_0-1608672631422.png

 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

 

View solution in original post

5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
I don't see a BY statement in your code. You actually have 2 BY variables, region and product. Did you mean to have a BY statement in your code?
Cynthia
Cynthia_sas
SAS Super FREQ

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:

Cynthia_sas_0-1608672631422.png

 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

 

acordes
Rhodochrosite | Level 12

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

 

 

acordes
Rhodochrosite | Level 12

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);
Cynthia_sas
SAS Super FREQ
Hi, yes, the Macro %DO loop approach is a very efficient technique. I tend to keep my macro examples simple because a lot of folks here in the forums haven't used SAS Macro programming. Good use of %DO to pass the entire string of desired brands.
Cynthia

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 697 views
  • 1 like
  • 2 in conversation