Using unistats with Lab data (2)

Last updated: 03 Jan 2012

Introduction

If you are reporting lab data with %unistats then you are almost certainly transposing the data by setting dstranstat= to a dataset name that you will display in a following step using "proc report". You will have effectively transposed by statistics keyword name such that the _statname value "MEAN" becomes a variable named "MEAN" and this will be a numeric variable and as such will have a fixed display format assigned to it. But in this we have a problem because of this display format being fixed. For different lab parameters we need to display different numbers of decimal places and this is not possible using a single numeric variable that can only have one format assigned to it. But there is a solution! Since the end of 2011, %unistats creates character variables for every numeric variable so that MEAN has a character variable equivalent named MEANSTR etc. and that you can apply a different format to this character variable. All you need to do is to set up a numeric variable that gives the number of decimal places for that parameter's value and declare this variable to the parameter dpvar= and the ---STR variable created will show the correct number of decimal places. It is as simple as that!

A real-life example

Here is a real life example from a QC macro I wrote at the start of 2012. There is a variable that I have named _dplaces that contains an integer that gives the number of decimal places accuracy and I have used that when calling %unistats. After the %unistats call I merge with some lab group ordering data that I have included so that the following "proc report" step makes more sense.
 
        /************************************
           Calculate Descriptive Statistics
         ************************************/
  *- Call unistats to calculate descriptive statistics with -;
  *- a transposed-by-statistic output dataset produced.     -;
  %unistats(dsin=_laball4,print=no,varlist=&labval,
  trtvar=&trtvar,trtfmt=$atrfmt.,leftstr=yes,
  byvars=tp labnm labparmstr,dpvar=_dplaces,
  nfmt=5.,stdfmt=5.,minfmt=5.,maxfmt=5.,meanfmt=5.,
  descstats=&descstat,dstranstat=_transtat);

        /************************
            Add Lab Group Info
         ************************/
  *- add in the lab group info -;
  proc sql noprint;
    create table _transtat2 as (
    select a.*, b.labgrp, b.labgrpx, b.labnmor
    from _transtat as a
    left join _labgrp as b
    on a.labnm=b.labnm
    ) order by labgrp, labgrpx;
  quit;
 

The list of numeric statistics variables will be the list of "keywords" held in &_statkeys_ and the corresponding character variables will have the same name but ending in "STR". A little later in the code I list these character variables that I need to use in a "proc report" step. Look carefully at the way I refer to them. Look for %suffix(STR,&_statkeys_) and %scan(&_statkeys_,&i,%str( ))STR
 
         /*******************************
                  Produce report
         *******************************/
  %let ncolw=8;
  %if %words(&_statkeys_) GT 6 %then %let ncolw=6;

  *- style=2 (XLAB 2) report with treatment arm as the across variable -;
  %if &style2 EQ Y %then %do;
    proc report missing headline headskip nowd split="@" data=_transtat2 spacing=2; 
      by labgrp labgrpx;
      columns ( "%sysfunc(repeat(%sysfunc(byte(131)),%eval(&repwidth-1)))"
                labnmor labparmstr labnm tp &trtvar,(%suffix(STR,&_statkeys_)) _foolrep); 
      define labnmor / group noprint;
      define labparmstr / group noprint; 
      define labnm / group noprint; 
      define tp / id group order=internal "Parameter/" "  Visit/" "  Difference from %lowcase(&bslnlbl)"
                  format=tpind. width=30 spacing=0 left;
      define &trtvar / across " " order=internal format=&_popfmt_ ; 
      %do i=1 %to %words(&_statkeys_);
        %let key=%scan(&_statkeys_,&i,%str( ))STR;
        %let spac=;
        %if &i EQ 1 %then %let spac=spacing=⪆
        %if &key EQ NMISSSTR %then %let colw=%sysfunc(max(7,&ncolw));
        %else %let colw=&ncolw;
        define &key / display width=&colw &spac right;
      %end;
      define _foolrep / noprint; 
      compute before labnm;
        line @1 labparmstr $char60.;
      endcompute;
      break after labnm / skip;
    run;
  %end;

Conclusion

You have seen how the number of decimal places can be changed using the dpvar= parameter and stored in the character variables that %unistats creates that you can then report using "proc report".

 

Use the "Back" button of your browser to return to the previous page.

contact the author
















SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.