Help using Base SAS procedures

PROC REPORT help....

Reply
N/A
Posts: 1

PROC REPORT help....

G'day I am attempting to use a "star" system for reporting with and would like to insert wingding "stars" conditional on a variable in the dataset. The conditional-if is not executing... HELP! (much obliged and thanks.....)

ods escapechar='^';

ods pdf file='temp.pdf';

proc report data=sashelp.class nowd ;

      col age new sex name;

      define new / format=$30. ;

      define sex / noprint ;

      define name / display;

      compute new/char ;

            if sex = "M" then new='^S={font_face=wingdings} ²'; else new='^S={font_face=wingdings} ²²²²²²';

      endcomp;

run;

ods pdf close;

Frequent Contributor
Posts: 81

Re: PROC REPORT help....

Posted in reply to tiwoodson

Hello,

You need to change the order of variables on the COLUMN statement. PROC REPORT processes variables in the order in which they are named on the COLUMN statement. Variables referenced in a COMPUTE block cannot refer to variables listed to their right in the COLUMN statement.

col age sex new name;

SAS Super FREQ
Posts: 8,869

Re: PROC REPORT help....

Posted in reply to tiwoodson

Hi:

  Well, you can't compute NEW the way your column statement is coded right now, since it is on the wrong side of SEX in the COLUMN statement. Look for previous postings on PROC REPORT and "left to right processing".

  Think of PROC REPORT as building each single report row one column item at a time. So first, PROC REPORT places AGE on the report row, then it places NEW on the report row. There's a COMPUTE block for NEW. However, at the point where PROC REPORT is trying to build NEW, the variable SEX has not been placed on the report row, so the COMPUTE block has no visibility of the value for SEX.  SEX can still be a NOPRINT item, it just has to be on the -other- side of  NEW if you want to use the SEX variable in the COMPUTE block for NEW. In the same fasion, when PROC REPORT is placing the SEX column on the report, it hasn't yet placed NAME on the report -- so if you wanted to do some form of highlighting for NEW based on NAME, that wouldn't work either.

  And, there's an easier way to do your code, I think. All you need to do is assign the correct hex value to NEW ('AB'x is the black star and 'B5'x is the white star in a black circle) -- to find the hex value for other Wingding characters, use Windows character map or look at a map of the Wingdings font. And then you don't need to use ODS ESCAPECHAR (unless you really want to for some other reason). See attached screenshot.

cynthia


Wingdings_char_map.jpgstarz_wingdings.jpg
Super User
Posts: 10,046

Re: PROC REPORT help....

Posted in reply to tiwoodson

Just as NickR said. You need to put sex variable(noprint) before new variable.

ods escapechar='^';

ods pdf file='temp.pdf';

proc report data=sashelp.class nowd ;

      column sex age new name;

      define sex/noprint;

      define new / format=$30. ;

      define name / display;

      compute new/char ;

            if sex = "M" then new='^S={font_face=wingdings} ²'; else new='^S={font_face=wingdings} ²²²²²²';

      endcomp;

run;

ods pdf close;

Ksharp

Ask a Question
Discussion stats
  • 3 replies
  • 569 views
  • 0 likes
  • 4 in conversation