BookmarkSubscribeRSS Feed
tiwoodson
Calcite | Level 5

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;

3 REPLIES 3
NickR
Quartz | Level 8

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;

Cynthia_sas
SAS Super FREQ

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
Ksharp
Super User

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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