Return to Archive

SAS Tip of the Month
June 2009

While at PharmaSUG I was asked a question as to how a percentage change value could be displayed prefixed by a '+' or '-'. This can be done in a picture format the following way:

   proc format;
      picture plusminus
          low-<0 = '0000.0' (prefix='-')
               0 = '0' (noedit)
         0<-high = '0000.0' (prefix='+');
   run;

Note that in this example we are displaying the values to one decimal place.

Now lets look at an example, displaying the Change from Baseline Percentage value to one decimal place:

   *--------------------------------------;
   * Set up display of Cycle/Day in report;
   *--------------------------------------;
   proc format;
      value $CycDay
        'C1D2' = 'Cycle 1, Day 2'
        'C1D3' = 'Cycle 1, Day 3'
        'C2D1' = 'Cycle 2, Day 1'
        'C2D2' = 'Cycle 2, Day 2'
        'C2D3' = 'Cycle 2, Day 3';
   run;
   
   *--------------------------------------;
   * For the purposes of this example, the;
   * values are coming in from a CARDS    ;
   * statement.                           ;
   *--------------------------------------;
   data BUN_ChangeFromBaseline;
      attrib TimePoint length=$4 format=$CycDay.
               label='TimePoint'
             PercentChange length=8 format=plusminus.
               label='% Change from Baseline';
      infile cards;
      input TimePoint $ PercentChange;
   cards;
   C1D2 -8.6
   C1D3 3.5
   C2D1 4.7
   C2D2 -3.7
   C2D3 -5.9
   ;
   run;
   
   *--------------------------------------;
   * Make sure order is correct.          ;
   *--------------------------------------;
   proc sort data=BUN_ChangeFromBaseline;
      by TimePoint;
   run;
   
   *--------------------------------------;
   * Generate listing                     ;
   *--------------------------------------;
   options byline nocenter;
   run;
   title1 "Listing of Percentage Change from Baseline for BUN values, at Timepoint";
   proc print data=BUN_ChangeFromBaseline noobs label;
      var TimePoint PercentChange;
   run;

The following output will appear in the Output Window:

   Listing of Percentage Change from Baseline for BUN values, at Timepoint
   
                     % Change
                       from
     TimePoint       Baseline
   
   Cycle 1, Day 2      -8.6
   Cycle 1, Day 3      +3.5
   Cycle 2, Day 1      +4.7
   Cycle 2, Day 2      -3.7
   Cycle 2, Day 3      -5.9

Note that the raw values were not changed into a text variable for display, as programs sometimes do.

I hope you find this months tip useful.

________________________________
Updated July 3, 2009