Help using Base SAS procedures

How to add superscripts to a cell according its value

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

How to add superscripts to a cell according its value

Hi

I am trying to produce a table template for a report. One column of table need to add superscript to the cell according to the cell value ( for example, if the value >1 then a super a need to add to that value). it seems that cellstyle and translate don't work. Does anyone can help on this quesitons.


Accepted Solutions
Solution
‎12-16-2011 10:42 AM
Super User
Posts: 9,681

Re: How to add superscripts to a cell according its value

Ou? Sorry. I don't notice this.

Just use picture format to replace numeric format. No problem.

proc format;
picture rf(default=40)
       low-1="9.999"
       1<-high="9.99 ~{super b}";
run;

data one;
input name :$40. age ratio;
if age lt 20 then name=catx(' ',name,'~{super a}');
format ratio rf.;
cards;
Mathew  14  0.75
Mark 15 0.975
Luck  37 12.59
John 48   2.75
Paul 45  0.735
;
run;
ods rtf file="c:\x.rtf";
ods escapechar="~"; 
proc report data=one nowd ;
run;
ods rtf close; 

Ksharp

View solution in original post


All Replies
PROC Star
Posts: 7,363

How to add superscripts to a cell according its value

Possibly the following paper might help: http://www.lexjansen.com/pharmasug/2007/po/po12.pdf

It uses a compute block to assign superscripts based on cell values.

Contributor
Posts: 20

Re: How to add superscripts to a cell according its value

the paper is useful for fixed string, but how about on the dynamic value? ( it seems the proc format

could do the trick, but I have not made it work on my data)

PROC Star
Posts: 7,363

Re: How to add superscripts to a cell according its value

Can you post some example data (perferably in the form of a datastep) and the code you tried?

Contributor
Posts: 20

Re: How to add superscripts to a cell according its value

data one;

input name$ age ratio;

cards;

Mathew  14  0.75

Mark 15 0.975

Luck  37 12.59

John 48   2.75

Paul 45  0.735

;

I would like add superscript "a" on the name whose age is less than 20 and add superscipt "b" on the number in ratio column that greater than 1.

ods rft file="c:\output\rtf"

ods escapechar="^";

proc format;

picture ratioform

low-1.0="9.999"

1.0-high="9.99^{super b}";/* I did not make this work, it add super b, but the decimal point is wrong*/

run;

proc template;

define table mytable;

     column name age ratio;

               /****need help on name super a*/

     define column ratio;

          header ="Ratio";

          format=ratioform.

     end;

end;

data _null_;

set one;

file print ods=(template="mytable");

put _ods_;

run;

ods rtf close;

Super User
Posts: 9,681

Re: How to add superscripts to a cell according its value

I tested it . No problem.

You should use numeric format not picture format.

proc format;
value rf(default=40)
       low-1="9.999"
       1<-high="9.99 ~{super b}";
run;

data one;
input name :$40. age ratio;
name=ifc(age lt 20,catx(' ',name,'~{super a}'),name);
format ratio rf.;
cards;
Mathew  14  0.75
Mark 15 0.975
Luck  37 12.59
John 48   2.75
Paul 45  0.735
;
run;
ods rtf file="c:\x.rtf";
ods escapechar="~"; 
proc report data=one nowd ;
run;
ods rtf close; 

Ksharp

Contributor
Posts: 20

Re: How to add superscripts to a cell according its value

Thank you, Ksharp. Your code is really helpful. The numeric format does not work for me because I want to add super b to 12.59  ( it should be 12.59 {super b} not 9.99{super b}. The picture format works fine this time. But the name {super a } works cool!!! and I learned a funcion IFC.  

Again, thank you very much!

Solution
‎12-16-2011 10:42 AM
Super User
Posts: 9,681

Re: How to add superscripts to a cell according its value

Ou? Sorry. I don't notice this.

Just use picture format to replace numeric format. No problem.

proc format;
picture rf(default=40)
       low-1="9.999"
       1<-high="9.99 ~{super b}";
run;

data one;
input name :$40. age ratio;
if age lt 20 then name=catx(' ',name,'~{super a}');
format ratio rf.;
cards;
Mathew  14  0.75
Mark 15 0.975
Luck  37 12.59
John 48   2.75
Paul 45  0.735
;
run;
ods rtf file="c:\x.rtf";
ods escapechar="~"; 
proc report data=one nowd ;
run;
ods rtf close; 

Ksharp

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 519 views
  • 0 likes
  • 3 in conversation