Hi,
I have test program and want to control the style of one field based on the value of another field in Proc report. The program I wrote to test this is below. The computed block doesn't work as the value of topzip is uninitialized. But it appears in the check debug file. ?
Thanks!
--Ben
data pcts;
input cust pct zip;
topzip+1;
if lag(cust)^=cust then topzip=1;
cards;
1 53 43058
1 17 43220
1 12 43235
1 7 43081
1 4 43214
;;;
proc format;
picture pct low-high= '000% of your clients reside in ';
run;
ods escapechar='^';
options papersize=(1.5in 2.4in);
proc report data=pcts split='\' out=check;
by cust;
column square pct zip topzip;
define topzip /noprint;
define pct /display format=pct. '^{unicode ''2605''x}' color=red width=10 flow right;
define zip /display 'You are located here' color=red left;
define square /display computed '';
compute square /character length=20;
square='^{unicode ''220e''x}';
if topzip=1 then call define('square','style','style={color=red}');
if topzip=2 then call define('square','style','style={color=green}');
if topzip=3 then call define('square','style','style={color=black}');
if topzip=4 then call define('square','style','style={color=orange}');
if topzip=5 then call define('square','style','style={color=blue}');
endcomp;
run;
column topzip square pct zip;
define topzip / display noprint;
PROC REPORT processes columns from left to right. Because square is to the left of topzip, topzip is not defined when the compute block for square is executed. I see that topzip is a non-printing column, so you should be able to just move it to precede square in the COLUMN statement.
column topzip square pct zip;
define topzip / display noprint;
Thanks much! I had it originally on the left side but had also left out the DISPLAY parameter. It generated the same 'unitialized' warning when it was not there.
This stuff is really slick... 🙂
Thanks!
-Ben
The default for numeric is to summarize so the name of the statistic associated with topzip would be something like topzip.sum (I think). I don't use PROC REPORT for summary but, I often make the same omission of type.
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.