BookmarkSubscribeRSS Feed
Ravikumarkummari
Quartz | Level 8

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.

 

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ravikumarkummari
Quartz | Level 8

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ravikumarkummari
Quartz | Level 8

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;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Ravikumarkummari
Quartz | Level 8

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

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
  • 7 replies
  • 1353 views
  • 0 likes
  • 2 in conversation