DATA Step, Macro, Functions and more

using the value of another field in a Proc Report compute block

Accepted Solution Solved
Reply
Regular Contributor
Posts: 179
Accepted Solution

using the value of another field in a Proc Report compute block

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;


Accepted Solutions
Solution
‎06-15-2016 01:45 PM
Respected Advisor
Posts: 3,799

Re: using the value of another field in a Proc Report compute block

Posted in reply to BenConner
   column topzip square pct zip; 
   define topzip / display noprint; 

View solution in original post


All Replies
Super Contributor
Posts: 394

Re: using the value of another field in a Proc Report compute block

Posted in reply to BenConner

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.

 

Solution
‎06-15-2016 01:45 PM
Respected Advisor
Posts: 3,799

Re: using the value of another field in a Proc Report compute block

Posted in reply to BenConner
   column topzip square pct zip; 
   define topzip / display noprint; 
Regular Contributor
Posts: 179

Re: using the value of another field in a Proc Report compute block

Posted in reply to data_null__

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... Smiley Happy

 

Thanks!

 

-Ben

Respected Advisor
Posts: 3,799

Re: using the value of another field in a Proc Report compute block

Posted in reply to BenConner

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 277 views
  • 0 likes
  • 3 in conversation