Showing posts with label REPORT. Show all posts
Showing posts with label REPORT. Show all posts

Tuesday, August 16, 2016

{nbspace x} in PROC REPORT

ods escapechar="^";

proc report data = statsp nowd split = '|' headline headskip
            style(report) = [asis = on PROTECTSPECIALCHARS=off outputwidth=9in]
            center missing contents="" spanrows;

define rowlbl  /order "Parameter" left width=20
                     style(column)=[/*font_weight=bold*/ cellwidth=2in asis=on]
                     style(header)=[just=left];

*** Use asis=on in DEFINE statement to make {nbspace x} in ROWLBL work

Wednesday, September 30, 2015

Apply color to PROC REPORT

Highlight a row:
 
compute __stresc;
  if index(__stresc,'>') then call define(_row_,"style","style={backgroundcolor=red}");
endcomp;


Highlight a cell:
 
compute __stresc;
   if index(__stresc,'>') then call define(_col_,"style","style={color=red}");
endcomp;


Color a row:

compute __stresc;
   if index(__stresc,'>') then call define(_row_,"style","style={color=red}");
endcomp;

Friday, November 21, 2014

Avoid the error of "no statistic associated with XXX." in PROC REPORT

One can avoid this error by putting a dummy analysis variable on the end of the COLUMN statement.  For example:

proc report data=test headline headskip split='~' nowd spanrows;
      column n vargrp trt, (timer, (statc)) dummy;
      define n /group noprint;
      define vargrp /group order=internal style(column)={cellwidth=1.2in} left ' ' id;
      define trt /across order=internal style(column)={cellwidth=0.6in} center ' ' ;
      define timer /across order=internal style(column)={cellwidth=0.6in} center ' ' ;
      define statc /display style(header column)={cellwidth=0.6in} center ' ';
      define dummy /computed noprint;
run;

Friday, March 28, 2014

A Couple of Proc Template for Report

proc template;
  define style timesrtf;
  parent=styles.journal;
  replace fonts /
     'BatchFixedFont' = ('Times',9pt)
     'TitleFont' = ('Times',12pt)
     'TitleFont2' = ('Times',9pt)
     'FootFont' = ('Times',9pt,Italic)
     'StrongFont' = ('Times',9pt,Bold)
     'EmphasisFont' = ('Times',9pt)
     'FixedEmphasisFont' = (Times,9pt)
     'FixedStrongFont' = (Times,9pt,Bold)
     'FixedHeadingFont' = (Times,9pt)
     'FixedFont' = (Times,9pt)
     'headingEmphasisFont' = ('Times',9pt)
     'headingFont' = ('Times',9pt)
     'docFont' = ('Times',9pt);
  style table from output /
      cellpadding = 2pt
      background=white
      rules=groups
      frame=void;
  style body from document /
      leftmargin=1in
      rightmargin=1in
      topmargin=1in
      bottommargin=0.5in;
  replace color_list  /
     'bgH' = white
     'fg' = black
     'bg' = white;
 end;
run;

proc template;
  define style mystyle;
  parent=styles.printer;
  replace fonts /
     'BatchFixedFont' = ('Courier',8pt)
     'TitleFont2' = ('Courier',9pt,Bold)
     'TitleFont' = ('Courier',9pt,Bold)
     'StrongFont' = ('courier',8pt,Bold)
     'EmphasisFont' = ('Courier',8pt)
     'FixedEmphasisFont' = (Courier,8pt)
     'FixedStrongFont' = (Courier,8pt,Bold)
     'FixedHeadingFont' = (Courier,8pt)
     'FixedFont' = (Courier,8pt)
     'headingEmphasisFont' = ('Courier',8pt)
     'headingFont' = ('Courier',8pt)
     'docFont' = ('Courier',8pt);
  style table from output /
      cellpadding = 1pt
      background=white
      rules=groups
      frame=void;
*      rules=all/*rows*//*groups*/
*     frame=hsides/*box*/;
  style body from document /
      leftmargin=0.36in
      rightmargin=0.25in
      topmargin=0.60in
      bottommargin=0.36in;
  replace color_list  /
     'link' = black
     'bgH' = white
     'fg' = black
     'bg' = white;
 end;
run;

Tuesday, January 4, 2011

Calculate new variables using the sum of other columns in PROC REPORT

%macro vol(type,desc);

proc report data=fmxx center headline headskip split='/';
      column site_id havevis &type.2 &type.3 &type.p1 &type.p2;

      define site_id / group id order=internal width=16 left 'Clinical Center'style(header)={cellwidth= 1.2in just=left} style(column)={cellwidth= 1.2in cellheight=0.17in just=left};
      define havevis / sum style(header)={cellwidth=.9in} 'All/Visits' center ;
      define &type.2 / sum style(header)={cellwidth=.9in} width=15 "Any/&desc" center ;
      define &type.3 / sum style(header)={cellwidth=.9in} width=15 "3+ Volumes/for &desc/n" center ;
      define &type.p1 / computed width=10 format=5.1 "3+ Volumes/for &desc/% (1)" center;
      define &type.p2 / computed width=10 format=5.1 "3+ Volumes/for &desc/% (2)" center;

      compute &type.p1;
            &type.p1=(&type.3.sum*100)/&type.2.sum;
      endcomp;
      compute &type.p2;
            &type.p2=(&type.3.sum*100)/havevis.sum;
      endcomp;
title1 " ";
run;

%mend;

%vol(head, Head);

If data is already summarized, use the following code for compute:

      compute &type.p1;
            _c5_=(_c4_*100)/_c3_;
      endcomp;
      compute &type.p2;
            _c6_=(_c4_*100)/_c2_;
      endcomp;

Tuesday, November 23, 2010

Label variable with special character

Create delta in the report and label:

ods escapechar='^';
ods rtf file='temp.rtf'; *** Can be HTML or PDF too;

proc report data=sashelp.class nowd ps=40;
      col age new;
      define new / format=$30. ;
/* for the RTF */
      compute new/char ;
            new='^S={font_face=symbol} D';
      endcomp;
/* for the listing */
      label age="my label" 'F0'X ;
run;

ods rtf close;


Create superscript:

Get superscripts for 0, 1, 2, and 3 in printed SAS output by using the extended characters specified in hexadecimal. The following example shows the superscripts for 0, 1, 2, and 3 using 'b0'x, 'b9'x, 'b2'x 'b3'x respectively:

data _null_;
      file print;
      put 'This is a superscript zero' 'b0'x;
      put 'This is a superscript one' 'b9'x;
      put 'This is a superscript two' 'b2'x;
      put 'This is a superscript three' 'b3'x;
run;

proc print label data=sashelp.class;
      label age=age'b2'x;
run;

Wednesday, February 10, 2010

Superscript, Subscript in RFT

data test;
length
secnam $15;input sortord secnam $ pvalue; 

cards;
   1 demog 0.8812
   2 ae 0.7112
   3 disposition 0.8112
   4 medicalhistory 0.9112
;
 

run;
 
ods listing close;
ods rtf file="Test.rtf" style=rtfout;
ods escapechar='\'; *** value not limited to \;

proc report data = test missing split="$" spacing=0 headline nowd;
     column sortord secnam pvalue;
     define sortord / order noprint;
     define secnam / order flow "Demographics$Variable\{super a}";
     define pvalue / display flow "ANOVA$P-Value\{sub p}";
footnote1 "testing\{super 1}";
footnote2 "new test\{sub 2}";
run;

Sunday, January 24, 2010

Jump start in PROC REPORT

PROC REPORT coding can get verbose, especially if there are a lot of variables requiring DEFINE statements. Here is a little trick which may speed things up a bit.

First, run PROC REPORT against the data set of interest, including the LIST option to list the code in the log and the NOEXEC option to prevent SAS from actually running the code. For example:

proc report data = sashelp.class list noexec ;
run ;

This should appear in the log:

PROC REPORT DATA=SASHELP.CLASS LS=96 PS=55 SPLIT="/" CENTER ;
    COLUMN Name Sex Age Height Weight;
    DEFINE Name / DISPLAY FORMAT= $8. WIDTH=8 SPACING=2 LEFT "Name" ;
    DEFINE Sex / DISPLAY FORMAT= $1. WIDTH=1 SPACING=2 LEFT "Sex" ;
    DEFINE Age / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Age" ;
    DEFINE Height / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Height" ;
    DEFINE Weight / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Weight" ;
RUN;

Copy the code to the program editor, and make any needed changes. Suppose we want average heights and weights by sex and age. Just insert the NOWD option in the PROC statement (assuming that interactive windowing is not needed), comment out the reference to NAME in the COLUMN statement and the DEFINE statement for NAME, and change the first option in each of the remaining DEFINE statements:

PROC REPORT DATA=SASHELP.CLASS LS=96 PS=55 SPLIT="/" CENTER nowd ;
    COLUMN /* Name */ Sex Age Height Weight;
*   DEFINE Name / DISPLAY FORMAT= $8. WIDTH=8 SPACING=2 LEFT "Name" ;
    DEFINE Sex / group FORMAT= $1. WIDTH=1 SPACING=2 LEFT "Sex" ;
    DEFINE Age / group FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Age" ;
    DEFINE Height / mean FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Height" ;
    DEFINE Weight / mean FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Weight" ;
RUN;

The output:

S
e
x Age Height Weight
F 11 51.3 50.5
    12 58.05 80.75
    13 60.9 91
    14 63.55 96.25
    15 64.5 112.25
M 11 57.5 85
    12 60.366667 103.5
    13 62.5 84
    14 66.25 107.5
    15 66.75 122.5
    16 72 150

Cosmetic refinements can be made by changing the WIDTH option for SEX and the FORMAT options for HEIGHT and WEIGHT.