The SAS Output Delivery System and reporting techniques

PROC Report Using Image and compute statement

Reply
N/A
Posts: 1

PROC Report Using Image and compute statement

I am current using SAS 9.4. I am trying to an insert arrow images in Proc Report but the compute statement is not working

I am getting CHANGE_IN_PCT is uninitialized in the Log and if statement is not working, here CHANGE_IN_PCT is a numeric data type variable.

Please check the below code:

PROC REPORT DATA=test NOWD;

COLUMNS TYPE  PREVIOUS_YEAR_PCT CURRENT_YEAR_PCT CHANGE_IN_PCT   ;

DEFINE TYPE / "Type";

DEFINE PREVIOUS_YEAR_PCT / "Avg Previous Year %";

DEFINE CURRENT_YEAR_PCT / "Avg Current Year %";

DEFINE CHANGE_IN_PCT /  "Change in %" ;

compute CHANGE_IN_PCT  ;

if  CHANGE_IN_PCT > 0 then

call define (_col_,"style","Style=

[postimage= 'F:\EIAS\School Grades\Dashboard Data\GreenUp.gif']");

endcomp;

RUN;

Trusted Advisor
Posts: 1,203

Re: PROC Report Using Image and compute statement

Hi,

Can we refer compute variable name in if statement?

Thanks,

compute CHANGE_IN_PCT ;

if  CHANGE_IN_PCT > 0 then

SAS Super FREQ
Posts: 8,721

Re: PROC Report Using Image and compute statement

Hi:

  Again, what is the usage of COMPUTE_IN_PCT in the DEFINE statement? Is the usage DISPLAY, ANALYSIS or COMPUTED -- does the variable exist in the input data set or are you creating it?

cynthia

Trusted Advisor
Posts: 1,203

Re: PROC Report Using Image and compute statement

Thanks Cynthia - This is true define statement will determine usage of COMPUTE_IN_PCT. Error in log "CHANGE_IN_PCT is uninitialized in the Log and if statement is not working" indicates that this variable is not in the dataset. It looks like this is being created using compute statement.

Regards,

Naeem

SAS Super FREQ
Posts: 8,721

Re: PROC Report Using Image and compute statement

Hi:

  Not true. For example, SASHELP.CLASS has 5 variables: NAME, AGE, SEX, HEIGHT and WEIGHT. I can easily generate an "unitialized" message if I don't use HEIGHT the correct way in a COMPUTE block. Run the attached code and you will see the message that HEIGHT is unitialized.

cynthia

ods _all_ close;
ods html file='c:\temp\geterror.html';

proc report data=sashelp.class nowd;
   column name age sex height weight;
   define name / order 'Name';
   define height / 'Height';
   compute height;
     if height gt 55 then
        call define(_col_,'style','{postimage="c:\temp\kermit.gif"}');
   endcomp;
run;
ods html close;

Trusted Advisor
Posts: 1,203

Re: PROC Report Using Image and compute statement

Hi,

Height variable is coming from the dataset and is on the column statement. When we are using this in a compute block, actually we are trying to use this as a temporary variable but it has already been defined as an analysis variable, this generates the error message.

Regards,

Naeem

SAS Super FREQ
Posts: 8,721

Re: PROC Report Using Image and compute statement

Hi:

  What is actually happening is that HEIGHT is being treated as an ANALYSIS variable with a default statistic of SUM. In the COMPUTE block, you are NOT trying to use HEIGHT as a 'temporary" variable, it is being referred to incorrectly in the COMPUTE block. In a COMPUTE block any reference to an existing numeric variable MUST use a COMPOUND name of variable.statistic, as explained here, in the doc:

Base SAS(R) 9.3 Procedures Guide, Second Edition Look at the section entitled:

"Four Ways to Reference Report Items in a Compute Block". You can use temporary items in a COMPUTE block, but in the code below, HEIGHT is a report item coming from the dataset and HEIGHT.SUM is the compound name that must be used in the COMPUTE block to change the style.

  So, for example, if you try this alternate code, you will see that the error goes away. I changed the CALL DEFINE to use a simple style override, since not everybody has kermit.gif on their system. In the code below the use of the simple reference to HEIGHT will get a note in the log for #2 and #3, the correct reference to HEIGHT.SUM (not a temporary item) will not generate a message.

cynthia

ods _all_ close;
ods html file='c:\temp\geterror.html';

proc report data=sashelp.class nowd;
  title1 '1) Will Get Error';
   column name age sex height weight;
   define name / order 'Name';
   define height / 'Height';
   compute height;
     if height gt 55 then
        call define(_col_,'style','style={background=lightgreen}');
   endcomp;
run;
     
proc report data=sashelp.class nowd;
  title1 '2) Will NOT Get Error';
   column name age sex height weight;
   define name / order 'Name';
   define height / 'Height';
   compute height;
     if height.sum gt 55 then
        call define(_col_,'style','style={background=lightgreen}');
   endcomp;
run;
  
proc report data=sashelp.class nowd;
  title1 '3) Will NOT Get Error';
   column name age sex height weight;
   define name / order 'Name';
   define height / 'Height';
   compute height;
     if height.sum gt 55 then
        call define(_col_,'style','style={postimage="c:\temp\arrow.gif"}');
   endcomp;
run;

         
ods html close;


height_uninit.pngArrow.gif
SAS Super FREQ
Posts: 8,721

Re: PROC Report Using Image and compute statement

Hi:

  Is your variable character or numeric. I suspect that it must be numeric, because if it is, you would need to refer to it by the compound name that is expected in the COMPUTE block. The PROC REPORT doc is very clear on when you need to use a compound name and without a specific usage in your DEFINE statement, PROC REPORT will assign the default usage for the type.

cynthia

Ask a Question
Discussion stats
  • 7 replies
  • 805 views
  • 2 likes
  • 3 in conversation