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.
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.
there no calculations included my process just i want to apply color.
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.
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;
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:
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.
Can you post a screenshot of what you mean. You can't compute "titles" within the report.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.