The SAS Output Delivery System and reporting techniques

how to apply a colour for a perticular row using call define

Reply
Frequent Contributor
Posts: 110

how to apply a colour for a perticular row using call define

Hi all,

i have a dataset like this 

title value1 value2 obs
policies 30 45 1
premium 45 50 2
product name 20 26 3
policies 47 89 4
premium 56 74 5
product name 12 45 6

 

i have to apply red colour for "product name".

i directly apply red colour in call define if title="product name" then

CALL DEFINE (_col_, "STYLE","STYLE={BACKGROUND=WHITE FOREGROUND=RED fontsize=12pt}");

the product name is changed by every week so i can't give directly product name.

 

so based on obs i have to apply red color for the row "product name"

i written below code 


PROC REPORT DATA=ds NOWD HEADLINE HEADSKIP NOHEADER
STYLE(REPORT)={outputwidth=4in BACKGROUND=WHITE FOREGROUND=BLACK BORDERCOLOR=WHITE FONT_FACE='CALIBRI' FONT_SIZE=11PT}
style(lines)={textdecoration=underline fontsize=12pt FONT_FACE='CALIBRI'
background=WHITE foreground=BLACK fontweight=bold};
COLUMN TITLE VALUE1 VALUE2 OBS;
DEFINE TITLE / STYLE={FONT_FACE='CALIBRI' FONT_SIZE=11PT };
DEFINE VALUE1 / STYLE={FONT_FACE='CALIBRI' FONT_SIZE=11PT };
DEFINE VALUE2 / STYLE={FONT_FACE='CALIBRI' FONT_SIZE=11PT };
DEFINE OBS/ NOPRINT;
COMPUTE title;
IF obs.sum in(3,6) THEN ;
CALL DEFINE (_col_, "STYLE","STYLE={BACKGROUND=WHITE FOREGROUND=RED fontsize=12pt}");
ENDCOMP;
COMPUTE BEFORE _PAGE_ ;
LINE @1"Top Performing Product:";
ENDCOMP;
RUN;

but unable to apply the color. is there any method for this 

please suggest me.

 

Thanks in advance.

 

Esteemed Advisor
Esteemed Advisor
Posts: 7,251

Re: how to apply a colour for a perticular row using call define

It would be far simpler if you did, in a datastep *before* the proc report, do your calculations, and apply a flag to variables to use later on, i.e. assign flags, and then call style based on the flags.

Frequent Contributor
Posts: 110

Re: how to apply a colour for a perticular row using call define

there no calculations included my process just i want to apply color.

Esteemed Advisor
Esteemed Advisor
Posts: 7,251

Re: how to apply a colour for a perticular row using call define

This is a calculation:

COMPUTE title;
IF obs.sum in(3,6) THEN ;
CALL DEFINE (_col_, "STYLE","STYLE={BACKGROUND=WHITE FOREGROUND=RED fontsize=12pt}");

 

Do this sum in your dataset and apply a flag.  Then if flag then ...

 

Also note, that as your only doing one line of code here, you do not want the semicolon after the "then".  If your doing a block of code then it would be:

... then do;

  ...

end;

 

Also, for clarity, use consistent casing/indetntation in your code, i.e. don't uppercase everything, it makes reading the code so much more difficult, and indetation also improves readability of the code.

Frequent Contributor
Posts: 110

Re: how to apply a colour for a perticular row using call define

doing calculation in datastep.

data ds;
set ds;
obs=_n_;
if obs in(3,6) then name="product";
run;

now applying proc report call define. But not applying colour.

compute title;
IF name="product" in(3,6) then
call define (_col_, "STYLE","STYLE={BACKGROUND=WHITE FOREGROUND=RED fontsize=12pt}");
endcomp;

 

 

Esteemed Advisor
Esteemed Advisor
Posts: 7,251

Re: how to apply a colour for a perticular row using call define

Well, there is a typo in the code first off:

IF name="product" in(3,6) then

Remove the in(3,6).

 

For the datastep I would do:

data ds;
  set ds;
  if _n_ in(3,6) then name=1;
run;

Now in your compute, have you tried setting the background of the cell?

compute title;
  if name="product" then call define (_col_, "style","style={background=red fontsize=12pt}");
endcomp;

 

Also, not clear on why you are "computing" a variable called title.  I would suggest you have a look at the many Traffic Lighting examples which are out there, for example this one which uses formats:

http://www2.sas.com/proceedings/sugi31/142-31.pdf

Frequent Contributor
Posts: 110

Re: how to apply a colour for a perticular row using call define

Hi

why i am computing title variable is in the variable title the row contains "product name" i want to apply color.

so based on obs and another variable name i tried for this.

but in datastep and and proc step i am unable to apply color.

Esteemed Advisor
Esteemed Advisor
Posts: 7,251

Re: how to apply a colour for a perticular row using call define

Can you post a screenshot of what you mean.  You can't compute "titles" within the report.

Ask a Question
Discussion stats
  • 7 replies
  • 561 views
  • 0 likes
  • 2 in conversation