The SAS Output Delivery System and reporting techniques

compute blocks premised on other variables

Reply
Regular Contributor
Regular Contributor
Posts: 170

compute blocks premised on other variables

Good afternoon!
Another dilemma that hopefully someone can help with in ODS..

I have a block of code that I am trying to do traffic lighting on one variable premised on another> reason being is that it does not fall simply to an under/over value but there is a second variable involved.
For example, an observation could be listed as 85% (40/50) in which depending on the number of months and number of observations, the 85% could be green or gray...I have calculated the values of colors in the dataset already.

Code is below-any help greatly appreciated.
Thanks again.

Lawrence


define color / NOPRINT DISPLAY ANALYSIS;
DEFINE FYTD /"FYTD";
compute FYTD ;

IF COLOR=1 THEN CALL DEFINE (_COL_,'style','style={background=light green}');
IF COLOR=3 THEN CALL DEFINE (_COL_,'style','style={background=pink}');
IF COLOR=2 THEN CALL DEFINE (_COL_,'style','style={background=light gray}');
ENDCOMP;

RUN;
SAS Super FREQ
Posts: 8,743

Re: compute blocks premised on other variables

Hi:
Without seeing ALL of your code, it is hard to comment. There are a few things that are possibilities
1) PROC REPORT left/right issues or
2) COMPOUND name issues

1)
... PROC REPORT works from LEFT to RIGHT. So if you have this:
[pre]
column something fytd color something2;
[/pre]

...then proc report will not know about COLOR when it is creating the report column for FYTD. But if you have this:

[pre]
column something color fytd something2;
[/pre]

...then PROC REPORT will have placed COLOR on the report row before it goes to execute the COMPUTE block for FYTD.

You cannot use COLOR in the COMPUTE block for FYTD unless COLOR is available for use. Remember that PROC REPORT does not have a Program Data Vector (like the DATA step) -- so in the above column statement, when PROC REPORT is placing the variable SOMETHING on the report row, it has NO visibility of the values for COLOR, FYTD or SOMETHING2. When PROC REPORT is placing COLOR on the report row, it has no visibility of FYTD values.

2)
Also, you might be having an issue with this:
[pre]
define color / NOPRINT DISPLAY ANALYSIS;
[/pre]

DISPLAY and ANALYSIS are conflicting usages. DISPLAY means the variable will not be summarized on a BREAK or RBREAK line. Then when you turn around and give a usage of ANALYSIS, you are telling PROC REPORT that you changed you mind and COLOR will be used for ANALYSIS and the default statistic should be the SUM statistic. If you are seeing messages like:
[pre]
NOTE: Variable color is uninitialized.
[/pre]

This would be an indication that PROC REPORT is expecting you to use the compound reference: COLOR.SUM ... because the last usage for COLOR was the ANALYSIS usage. If you want to use the simple reference name of COLOR, then keep only the usage of DISPLAY. If you want to use the compound reference for COLOR, then keep only the usage of ANALYSIS.

But without seeing more of your code, or your LOG with error messages, it's hard to say. The code below worked for me. Consider the code below. The trafficlighting for AGE and HEIGHT work, however, the trafficlighting for NAME does not work because of the LEFT-to-RIGHT workings of PROC REPORT.

cynthia
[pre]
data class;
set sashelp.class(obs=3);
color = _n_;
run;

ods html file='c:\temp\tlite.html' style=sasweb;
proc report data=class nowd;
column name color sex age height;
define name / order;
define color / display noprint;
define sex / display noprint;
define age / display;
define height / display;
compute name;
** this will NOT work;
IF COLOR=1 THEN CALL DEFINE (_COL_,'style','style={background=light green}');
IF COLOR=3 THEN CALL DEFINE (_COL_,'style','style={background=pink}');
IF COLOR=2 THEN CALL DEFINE (_COL_,'style','style={background=light gray}');
ENDCOMP;
compute age;
** this WILL work;
IF COLOR=1 THEN CALL DEFINE (_COL_,'style','style={background=light green}');
IF COLOR=3 THEN CALL DEFINE (_COL_,'style','style={background=pink}');
IF COLOR=2 THEN CALL DEFINE (_COL_,'style','style={background=light gray}');
ENDCOMP;
compute height;
if name = 'Alfred' and sex = 'M' then
call define(_col_,'style','style={foreground=cyan}');
endcomp;
run;
ods html close;
[/pre]
Regular Contributor
Regular Contributor
Posts: 170

Re: compute blocks premised on other variables

Cynthia;
Thanks for the solutions. I was just reading about order when the thread came through. Also the tip on the analysis/display helped immensely.
Thanks again!
Ask a Question
Discussion stats
  • 2 replies
  • 175 views
  • 0 likes
  • 2 in conversation