Using unistats with Lab data (1)

Last updated: 27 Sep 2011

Introduction

It is an easy mistake to think that %unistats is limited to producing reports as previously shown on the %unistats page. However, this would be a mistake. %unistats can not and does not produce reports! The reports you were looking at were produced by a macro called %unicatrep and were only produced because the macro %unistats was called. %unicatrep handles one type of report only. The "cat" in its name tells you that it handles reports that contain categories and furthermore it is limited to where you have one observation per subject. If you are producing a table using lab data or vital signs data then you will want to display descriptive statistics, typically for N, Min, Max, Mean and STD, and not categories and you will have more than one observation per subject corresponding to the different visits. The macro %unicatrep can only show descriptive statistics vertically listed so if you want to show these descriptive statistics horizontally you have to produce the report using "proc report". In any case, %unicatrep has no room to display visits. However, even if you are using "proc report", you still use %unistats to calculate the descriptive statistics and doing this is very easy, as you will see.

What you will see below is a report used on actual study data that was sent to me. The data is blinded and I have permission to web it. The dataset is called vital_vert and I have stored it in the Spectre folder. It calls two formats that I do not have and two of the variables named _name_ and _label_ have to be changed  since this would clash with the transposes done inside the %unistats macro. If you browse this data then make sure you use the "nofmterr" option because of the missing formats. Although this is inconvenient, I want you to realise that this is real study data that I am using so I am not making the data up to suit my macros. %unistats and %npcttab should be able to do all your safety reporting. It is just a case of getting to know what the macros do and the way they work. %npcttab can give you good reports and %unistats can give you a good category report, using a call to %unicatrep, but to get other reports from %unistats you have to use your skills with "proc report". But %unistats can do a lot of work for you. Importantly, you should never have to transpose your data in your code because %unistats can do that for you. That way, your programs should take the form of calls to %npcttab or %unistats and the rest of the work will be no more than merges and "proc report" steps. Data manipulation should be done inside %npcttab or %unistats and not in your code. This simplifies the validation process.

The code

To run this code, you will have to place the vital_vert dataset in your Spectre folder, though if you wish to store it elsewhere, the change to the libname statement in the code below should be obvious. Remember that I have to use the "nofmterr" option as although I have the data, I do not have the formats. I will cancel one of the formats and set up my own treatment format.

Note in the code below that I am using this data as the population data input to %popfmt to give the population totals. Normally, I would use a population dataset for this, but I do not have one to go with this data.

I want you to look at the call to %unistats in the code below. It is very simple. Note the "byvars". %unistats will keep these variables in the output dataset so that I can use them to produce the report I want to when I call "proc report". I will want to show the parameter label and the visit number on my report and I want to use the short parameter name to order the output (although I won't display it).
 
/* Demonstration 1 of %unistats used to create a lab/vital signs table */

options nofmterr nocenter ls=132;

libname spectre "C:\spectre";
 

proc format;
  value drug
    1="Drug A"
    2="Drug B"
 ;
run;
 

*- fix some variable names and change some formats -;
data vital;
  set spectre.vital_vert;
  format treat drug. visit;
  rename _name_=name _label_=label;
  label treat="Treatment Arm";
run;
 

%popfmt(vital,treat,uniqueid=pat)
 

%unistats(dsin=vital,print=no,
varlist=value,
byvars=visit name label,
descstats=N Min Mean Max STD.,
minfmt=3.,maxfmt=3.,
dstranstat=transtat)
 

proc report missing headline nowd split="@" data=transtat spacing=2;
  columns name label visit treat,(n min mean max std);
  define name / group order=internal noprint;
  define label / group "Parameter" width=32;
  define visit / group order=internal "Visit" width=5 f=2. center;
  define treat / across ;
  define n / sum spacing=5;
  define min / sum;
  define mean / sum;
  define max / sum;
  define std / sum spacing=1;
  break after name / skip;
run;

Before we look at the output, I thought I would mention something about the last "proc report" step in the code above. If you look at the "proc report" code above, you will see that I have asked for the "sum" of n, min, mean, max and std. You might not feel comfortable using "sum" in your code as it has the potential of adding two or more numbers together (I know it won't in this case). But there is a trick you can use with proc report to allow you to use "display" instead of "sum". What you do is use a non-existent "noprint" variable that "proc report" will treat as "computed" and then it will work the same. Here is the altered "proc report" code. The variable "_foolrep" is not present in the input dataset.
 
proc report missing headline nowd split="@" data=transtat spacing=2; 
  columns name label visit treat,(n min mean max std) _foolrep; 
  define name / group order=internal noprint; 
  define label / group "Parameter" width=32; 
  define visit / group order=internal "Visit" width=5 f=2. center; 
  define treat / across ; 
  define n / display spacing=5; 
  define min / display; 
  define mean / display; 
  define max / display; 
  define std / display spacing=1; 
  define _foolrep / noprint;
  break after name / skip; 
run; 

The output

Here is the output. It is a very simple report. In reality you might want one parameter per page. You might even want to show the descriptive statistics of the "change from baseline" following the value descriptive statistics. You can do all of these things. You just have to make sure that all the variables you need to organise the report are declared to the "byvars=" parameter and then getting the report to look right is up to your "proc report" skills.
 
                                                                     Treatment Arm
                                                        Drug A                          Drug B
                                                        (N=19)                          (N=21)
  Parameter                         Visit       N  Min   Mean  Max   STD.       N  Min   Mean  Max   STD.
  _______________________________________________________________________________________________________
  Diastolic blood pressure [mmHg]     1        19   60   72.9   90   7.13      21   60   76.0  100  12.71
                                      2        19   60   71.6   90   7.46      21   60   73.3  100   9.40
                                      3        17   60   73.5   90   9.15      19   70   78.2   90   7.30
                                      4        13   60   70.8   80   7.32      20   60   73.6   90   8.22
                                      5        14   60   72.1   90   8.71      19   60   72.6   85   8.23
                                      6        12   60   70.8   85   7.02      18   60   77.2  100  12.63
                                      7        13   60   71.5   90   9.66      18   60   76.1   90   9.48

  Puls [/min]                         1        19   45   68.8   88  10.05      21   56   69.4   88   7.79
                                      2        19   45   67.4   84   9.60      21   52   68.8   82   8.43
                                      3        17   54   69.3   88   9.35      19   58   70.6   88   8.30
                                      4        13   60   68.6   88   7.41      20   60   68.5   80   6.72
                                      5        14   45   65.5   88  12.46      19   48   70.2   80   7.88
                                      6        12   50   68.5   88  10.52      18   52   69.2   92   9.16
                                      7        13   54   71.8   92  10.85      18   60   72.2   84   6.50

  Systolic blood pressure [mmHg]      1        19  100  118.2  140  12.38      21   90  118.1  150  17.99
                                      2        19  100  113.4  130   8.98      21   95  114.5  130  12.44
                                      3        17  100  118.2  140  11.85      19  100  122.1  140  13.16
                                      4        13  100  113.5  130  11.97      20  100  120.8  150  13.60
                                      5        14  100  115.7  140  12.84      19   85  115.3  140  15.50
                                      6        12  100  115.0  135  10.66      18   90  121.1  170  20.62
                                      7        13  100  117.3  140  12.18      18  100  118.6  150  12.10

 

Another code version

It is best if you show the statistics horizontally when you are showing the visits vertically as I have done above. If you have more than two treatment arms and the report becomes too wide then you could show two treatment arms on one page and the rest on the next page. You could use two calls to "proc report" to do that and use a "where" clause and select on "treat". So the next piece of code and its output is not the recommended way of doing things but if it were a requirement that both the visit and the statistics were shown vertically then it could be done like this. Note that in the call to %unistats I am asking that the output dataset be transposed by treatment group. Because I want this code to be generic and be able to cope with any number of treatment arms, I interrogate the global macro variable _trtvarlist_ , created by the %popfmt macro, which contains a list of the transposed variable names. I will use what it contains to create "define" statements for each of the transposed variables in the "proc report" step.
 
/* Demonstration 2 of %unistats used to create a lab/vital signs table */

options nofmterr nocenter ls=132;

libname spectre "C:\spectre";
 

proc format;
  value drug
    1="Drug A"
    2="Drug B"
 ;
run;
 

*- fix some variable names and change some formats -;
data vital;
  set spectre.vital_vert;
  format treat drug. visit;
  rename _name_=name _label_=label;
  label treat="Treatment Arm";
run;
 

%popfmt(vital,treat,uniqueid=pat)
 

%unistats(dsin=vital,print=no,
varlist=value,
byvars=visit name label,
descstats=N Min Mean Max STD.,
minfmt=3.,maxfmt=3.,
dstrantrt=trantrt)
 

%macro rep;
proc report missing headline nowd split="@" data=trantrt spacing=2;
  columns name label visit _statord _statlabel ("__Treatment Arm__" " " &_trtvarlist_);
  define name / order order=internal noprint;
  define label / order "Parameter" width=32;
  define visit / order order=internal "Visit" width=5 f=2. center;
  define _statord / order order=internal noprint;
  define _statlabel / order "Statistic" width=11;
  %do i=1 %to %words(&_trtvarlist_);
    define %scan(&_trtvarlist_,&i,%str( )) / display;
  %end;
  break after visit / skip;
run;
%mend rep;
%rep

The second output

                                                        _____Treatment Arm______

                                                        Drug A       Drug B
  Parameter                         Visit  Statistic    (N=19)       (N=21)
  ______________________________________________________________________________
  Diastolic blood pressure [mmHg]     1    N             19           21        
                                           Min           60           60        
                                           Mean          72.9         76.0      
                                           Max           90          100        
                                           STD.           7.13        12.71     

                                      2    N             19           21        
                                           Min           60           60        
                                           Mean          71.6         73.3      
                                           Max           90          100        
                                           STD.           7.46         9.40     

                                      3    N             17           19        
                                           Min           60           70        
                                           Mean          73.5         78.2      
                                           Max           90           90        
                                           STD.           9.15         7.30     

                                      4    N             13           20        
                                           Min           60           60        
                                           Mean          70.8         73.6      
                                           Max           80           90        
                                           STD.           7.32         8.22     

                                      5    N             14           19        
                                           Min           60           60        
                                           Mean          72.1         72.6      
                                           Max           90           85        
                                           STD.           8.71         8.23     

                                      6    N             12           18        
                                           Min           60           60        
                                           Mean          70.8         77.2      
                                           Max           85          100        
                                           STD.           7.02        12.63     

                                      7    N             13           18        
                                           Min           60           60        
                                           Mean          71.5         76.1      
                                           Max           90           90        
                                           STD.           9.66         9.48     

  Puls [/min]                         1    N             19           21        
                                           Min           45           56        
                                           Mean          68.8         69.4      
                                           Max           88           88        
                                           STD.          10.05         7.79     

                                      2    N             19           21        
                                           Min           45           52        

                                                        _____Treatment Arm______

                                                        Drug A       Drug B
  Parameter                         Visit  Statistic    (N=19)       (N=21)
  ______________________________________________________________________________
  Puls [/min]                         2    Mean          67.4         68.8      
                                           Max           84           82        
                                           STD.           9.60         8.43     

                                      3    N             17           19        
                                           Min           54           58        
                                           Mean          69.3         70.6      
                                           Max           88           88        
                                           STD.           9.35         8.30     

                                      4    N             13           20        
                                           Min           60           60        
                                           Mean          68.6         68.5      
                                           Max           88           80        
                                           STD.           7.41         6.72     

                                      5    N             14           19        
                                           Min           45           48        
                                           Mean          65.5         70.2      
                                           Max           88           80        
                                           STD.          12.46         7.88     

                                      6    N             12           18        
                                           Min           50           52        
                                           Mean          68.5         69.2      
                                           Max           88           92        
                                           STD.          10.52         9.16     

                                      7    N             13           18        
                                           Min           54           60        
                                           Mean          71.8         72.2      
                                           Max           92           84        
                                           STD.          10.85         6.50     

  Systolic blood pressure [mmHg]      1    N             19           21        
                                           Min          100           90        
                                           Mean         118.2        118.1      
                                           Max          140          150        
                                           STD.          12.38        17.99     

                                      2    N             19           21        
                                           Min          100           95        
                                           Mean         113.4        114.5      
                                           Max          130          130        
                                           STD.           8.98        12.44     

                                      3    N             17           19        
                                           Min          100          100        
                                           Mean         118.2        122.1      
                                           Max          140          140        

                                                        _____Treatment Arm______

                                                        Drug A       Drug B
  Parameter                         Visit  Statistic    (N=19)       (N=21)
  ______________________________________________________________________________
  Systolic blood pressure [mmHg]      3    STD.          11.85        13.16     

                                      4    N             13           20        
                                           Min          100          100        
                                           Mean         113.5        120.8      
                                           Max          130          150        
                                           STD.          11.97        13.60     

                                      5    N             14           19        
                                           Min          100           85        
                                           Mean         115.7        115.3      
                                           Max          140          140        
                                           STD.          12.84        15.50     

                                      6    N             12           18        
                                           Min          100           90        
                                           Mean         115.0        121.1      
                                           Max          135          170        
                                           STD.          10.66        20.62     

                                      7    N             13           18        
                                           Min          100          100        
                                           Mean         117.3        118.6      
                                           Max          140          150        
                                           STD.          12.18        12.10     
 
 

Conclusion

These are just two simple reports that you can produce with lab or vital signs data. The %unistats macro does not limit you. You just have to make sure that all the variables you need are defined to the "byvars=" parameter call and then producing the report is up to your "proc report" skills.

I am hoping for more datasets to be sent to me so that I can demonstrate how more complex lab/vital signs tables can be produced. That is the reason the title of this page has a "(1)" in it, signifying this is the first of such a demonstration.
 


 

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.