Help using Base SAS procedures

Proc Report Compute to Change Text Color

Reply
Contributor
Posts: 20

Proc Report Compute to Change Text Color

I thought this code would change the font color of a fieldf based on the value of another field in the columns:

compute id_rssd;

    if changed_event = '0' then do;

        call define (_col_, 'style', 'style=[foreground=blue]');

    end;

    if changed_event = '1' then do;

        call define (_col_, 'style', 'style=[foreground=green]');

    end;

endcomp;

But it didn't do anything.  The text came out black.

Attachment
Super User
Posts: 10,020

Re: Proc Report Compute to Change Text Color

Because id_rssd is before changed_event in COLUMN,  you can't ask change something behind id_rssd when you compute id_rssd .so change compute name .

compute changed_event;

    if changed_event = '0' then do;

        call define (_col_, 'style', 'style=[foreground=blue]');

    end;

    if changed_event = '1' then do;

        call define (_col_, 'style', 'style=[foreground=green]');

    end;

endcomp;

And better post questions about proc report at ODS and Base Reporting  later on. Cynthia will give you professional service .

Xia Keshan

Contributor
Posts: 20

Re: Proc Report Compute to Change Text Color

No improvement.

I also tried the following but it didn't help either:

Let me better explain what I'm trying to do:

I've got to define a display field to point to a url (this is working).

compute rssd_url;

     call define ('id_rssd','url',rssd_url);

endcomp;

I then need to change the color of the text based on the value of another field (which is not working):

compute id_rssd;

     If changed_event = '0' then do:

          call define (_col_, 'style', 'style=[foreground=blue]');

     end;

     If changed_event = '1' then do;

          call define (_col_, 'style', 'style=[foreground=green]');

     end;

endcomp;

Super User
Posts: 10,020

Re: Proc Report Compute to Change Text Color

Then post some sample data and code as short as you can , so I can test if it is worked.

SAS Super FREQ
Posts: 8,862

Re: Proc Report Compute to Change Text Color

Hi:

  It is not entirely clear to me what you want to do. It seems that you want to do 2 things in 1 cell -- make the cell contents a clickable hyperlink and change the color of the text in the cell. But, depending on the destination, you may not be able to change the color of URL text. URL hyperlinks are generally set off from "regular" text in some way, like this: http://www.sas.com -- note how most of my text is black but the hyperlink is colored blue. Once you designate some text as a hyperlink, it takes on the hyperlink characteristics. I do not believe you can change the color. You might check with Tech Support, though. For HTML-based destinations, there are some style attributes LINKCOLOR and VISITEDLINKCOLOR that I believe will work to change the color of hyperlink/URL text, but I notice that you are not creating HTML output, so I don't think that LINKCOLOR will work with TAGSETS.EXCELXP -- but that is a question for Tech Support.

cynthia

Contributor
Posts: 20

Re: Proc Report Compute to Change Text Color

Posted in reply to Cynthia_sas

It works if changed_event is placed before id_rssd in the columns statement and if you do it all in one compute statement:

CorrectCompute.jpg

SAS Super FREQ
Posts: 8,862

Re: Proc Report Compute to Change Text Color

Hi:

  That makes sense. CHANGED_EVENT would have to appear before ID_RSSD in the column statement for the COMPUTE block to work. PROC REPORT works on a left-to-right basis and it only generates 1 report row at a time, one column at a time. So if you have this COLUMN statement:

column name age height weight;


          Then, based on how PROC REPORT works, in a COMPUTE block for NAME, you could NOT test AGE. That's because at the point in time when PROC REPORT is writing NAME to the report row, it has not yet written AGE. So AGE is technically NOT available to be tested.
     

  But if you had this COLUMN statement:

column age name height weight;
     

  Then, you COULD test AGE in the COMPUTE block for NAME because at the point in time when NAME is being handled, the value for AGE has already been put on the report row. PROC REPORT does NOT have a "program data vector" like a DATA step program, so there is only visibility of what has been placed on the report row, working from left to right, based on the COLUMN statement order of variables.


         This is something about PROC REPORT that is explained in the documentation and in our Report Writing class. The relevant documentation topics are: "Concepts: REPORT Procedure"
and "How Proc Report Builds A Report" -- you should be able to find them for your version of SAS by searching on the support.sas.com web site.  

       

cynthia

Ask a Question
Discussion stats
  • 6 replies
  • 745 views
  • 0 likes
  • 3 in conversation