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

I would like to change the background to yellow when ydoi=2010.
ydoi equals 2010 and 2011.

Any ideas?
Thank you.

proc report data=month_tots1 nowd contents="Claims" out=test
style(header)=[font_weight=bold background=CX90D9D7 /*very light bluish green*/];
options missing='';
column mdoi ydoi, (msd_tot o_tot);
define mdoi / group "Month" format=mof. order=data style(column)={just=l};
define ydoi / across "" format=ydoif. order=data;
define msd_tot / 'MSD';
define o_tot / 'OD';
compute mdoi;
  if mdoi=. then call define(_row_,"style","style=[background=CXE599A7]");
endcomp;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  You will have to venture into the world of ACROSS variable naming to do what you want to do. When PROC REPORT builds a report, it will assign ABSOLUTE column numbers to the variables that are underneath an ACROSS variable.

  So, for example in the attached screen shot, the abolute column numbers can be determined by knowing that there are 2 possible values for YEAR and you have 2 variables under each year. So _C2_ and _C3_ are the 2010 values and _C4_ and _C5_ are the 2011 values. If you only wanted to highlight the MSD_TOT value for 2010, then you would apply your CALL DEFINE to _C2_. If you wanted to highlight both the MSD_TOT and the O_TOT values for 2010, then you would apply your CALL DEFINE to _C2_ and _C3_.

cynthia

options missing='';
ods listing close;

data month_tots1;
  set sashelp.prdsale;
  where quarter=1 and region = 'EAST' and
     country = 'CANADA' ;
  if year = 1993 then year = 2010;
  else if year = 1994 then year = 2011;
  mdoi = month;
  ydoi = year;
  msd_tot = actual;
  o_tot = predict;
run;
         
** change all 4 columns to different colors;
ods html file='c:\temp\across_rep.html' style=sasweb;
proc report data=month_tots1 nowd contents="Claims"
            out=test
   style(header)=[font_weight=bold background=CX90D9D7];
column mdoi ydoi, (msd_tot o_tot);
define mdoi / group "Month" f=monname3. order=data
       style(column)={just=l};
define ydoi / across "" format=4. order=data;
define msd_tot / 'MSD' f=comma8.;
define o_tot / 'OD' f=comma8.;
compute mdoi;
  if mdoi=. then
     call define(_row_,"style",
                       "style=[background=CXE599A7]");
endcomp;
compute msd_tot;
  call define('_c2_',"style","style=[background=yellow]");
  call define('_c4_',"style","style=[background=cyan]");
endcomp;
compute o_tot;
  call define('_c3_',"style","style=[background=pink]");
  call define('_c5_',"style","style=[background=green]");
endcomp;
run;
ods html close;

                         

** change 2010 columns to yellow;
** change 2011 columns to cyan;

  
ods html file='c:\temp\across_year.html' style=sasweb;
proc report data=month_tots1 nowd contents="Claims"
     style(header)=[font_weight=bold background=CX90D9D7];
column mdoi ydoi, (msd_tot o_tot);
define mdoi / group "Month" f=monname3. order=data
       style(column)={just=l};
define ydoi / across "" format=4. order=data;
define msd_tot / 'MSD' f=comma8.;
define o_tot / 'OD' f=comma8.;
compute mdoi;
  if mdoi=. then
     call define(_row_,"style",
                       "style=[background=CXE599A7]");
endcomp;
             
** _c2_, _c3_ are 2010;
** _c4_, _c5_ are 2011;
compute msd_tot;
  call define('_c2_',"style","style=[background=yellow]");
  call define('_c4_',"style","style=[background=cyan]");
endcomp;
compute o_tot;
  call define('_c3_',"style","style=[background=yellow]");
  call define('_c5_',"style","style=[background=cyan]");
endcomp;
run;

           
ods html close;


style_across.jpgshow_absolute.jpg

View solution in original post

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

Hi:

  You will have to venture into the world of ACROSS variable naming to do what you want to do. When PROC REPORT builds a report, it will assign ABSOLUTE column numbers to the variables that are underneath an ACROSS variable.

  So, for example in the attached screen shot, the abolute column numbers can be determined by knowing that there are 2 possible values for YEAR and you have 2 variables under each year. So _C2_ and _C3_ are the 2010 values and _C4_ and _C5_ are the 2011 values. If you only wanted to highlight the MSD_TOT value for 2010, then you would apply your CALL DEFINE to _C2_. If you wanted to highlight both the MSD_TOT and the O_TOT values for 2010, then you would apply your CALL DEFINE to _C2_ and _C3_.

cynthia

options missing='';
ods listing close;

data month_tots1;
  set sashelp.prdsale;
  where quarter=1 and region = 'EAST' and
     country = 'CANADA' ;
  if year = 1993 then year = 2010;
  else if year = 1994 then year = 2011;
  mdoi = month;
  ydoi = year;
  msd_tot = actual;
  o_tot = predict;
run;
         
** change all 4 columns to different colors;
ods html file='c:\temp\across_rep.html' style=sasweb;
proc report data=month_tots1 nowd contents="Claims"
            out=test
   style(header)=[font_weight=bold background=CX90D9D7];
column mdoi ydoi, (msd_tot o_tot);
define mdoi / group "Month" f=monname3. order=data
       style(column)={just=l};
define ydoi / across "" format=4. order=data;
define msd_tot / 'MSD' f=comma8.;
define o_tot / 'OD' f=comma8.;
compute mdoi;
  if mdoi=. then
     call define(_row_,"style",
                       "style=[background=CXE599A7]");
endcomp;
compute msd_tot;
  call define('_c2_',"style","style=[background=yellow]");
  call define('_c4_',"style","style=[background=cyan]");
endcomp;
compute o_tot;
  call define('_c3_',"style","style=[background=pink]");
  call define('_c5_',"style","style=[background=green]");
endcomp;
run;
ods html close;

                         

** change 2010 columns to yellow;
** change 2011 columns to cyan;

  
ods html file='c:\temp\across_year.html' style=sasweb;
proc report data=month_tots1 nowd contents="Claims"
     style(header)=[font_weight=bold background=CX90D9D7];
column mdoi ydoi, (msd_tot o_tot);
define mdoi / group "Month" f=monname3. order=data
       style(column)={just=l};
define ydoi / across "" format=4. order=data;
define msd_tot / 'MSD' f=comma8.;
define o_tot / 'OD' f=comma8.;
compute mdoi;
  if mdoi=. then
     call define(_row_,"style",
                       "style=[background=CXE599A7]");
endcomp;
             
** _c2_, _c3_ are 2010;
** _c4_, _c5_ are 2011;
compute msd_tot;
  call define('_c2_',"style","style=[background=yellow]");
  call define('_c4_',"style","style=[background=cyan]");
endcomp;
compute o_tot;
  call define('_c3_',"style","style=[background=yellow]");
  call define('_c5_',"style","style=[background=cyan]");
endcomp;
run;

           
ods html close;


style_across.jpgshow_absolute.jpg
gzr2mz39
Quartz | Level 8

Is there any way to avoid overriding this compute block:

compute mdoi;
if mdoi=. then call define(_row_,"style","style=[background=CXE599A7]" /*light pink*/);
endcomp;

other than creating compute blocks like this for each variable where I want to change the background color of the column (where ydoi=2010)?

compute msd_tot;
call define('_c6_',"style","style=[background=CXECEDEC]");
if mdoi=. then call define('_c6_',"style","style=[background=CXE599A7]");
endcomp;

Thank you.

Cynthia_sas
SAS Super FREQ

Most of the methods boil down to some kind of respecification like this or logic change. But, you could specify things differently. I don't have any missing values for my version of the MDOI variable, but if I use logic to highlight the row if MDOI = "Mar" with my fake data, I do get the entire row for MDOI='Mar' as pink. The trick is avoiding any possible style "collisions" by making sure that you only change the row to pink when MDOI is some value and flipping the logic for the ACROSS items.

cynthia

compute mdoi;

  if put(mdoi,monname3.)='Mar' then

     call define(_row_,"style",

                       "style=[background=CXE599A7]");

endcomp;

** _c2_, _c3_ are 2010;

** _c4_, _c5_ are 2011;

compute msd_tot;

  if put(mdoi,monname3.)ne 'Mar' then do;

    call define('_c2_',"style","style=[background=yellow]");

    call define('_c4_',"style","style=[background=cyan]");

  end;

endcomp;

compute o_tot;

  if put(mdoi,monname3.)ne 'Mar' then do;

    call define('_c3_',"style","style=[background=yellow]");

    call define('_c5_',"style","style=[background=cyan]");

  end;

endcomp;

sas-innovate-2024.png

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.

 

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