Proc Reports!!!



                  Although you can customize the output produced by PROC PRINT, there are times when
you need a bit more control over the appearance of your report. PROC REPORT was developed to fit this need. Not only can you control the appearance of every column of your report, you can produce summary reports as well as detail listings.

                  Two very useful features of PROC REPORT, multiple-panel reports and text wrapping within a column. We will look more about Proc Report by the following example.

#Problem:

                Using the SAS data set Blood Pressure we have to create a new variable called Hypertensive which is mentioned as Yes for females (Gender=F) if the SBP is greater than 138 or the DBP is greater than 88 and No otherwise. For males (Gender=M), Hypertensive is defined as Yes if the SBP is over 140 or the DBP is over 90 and No otherwise.

#Data set:


*Creating Bloodpressure dataset;
data A15028.A28_bloodpressure;
   input Gender : $1. 
         Age
         SBP
         DBP;
datalines;
M 23 144 90
F 68 110 62
M 55 130 80
F 28 120 70
M 35 142 82
M 45 150 96
F 48 138 88
F 78 132 76
;

#Solution:


title "Hypertensice Patients";
proc report data=A15028.A28_bloodpressure nowd;
column Gender SBP DBP Hypertensive;
define Gender / Group width=6;
define SBP / display width=5;
define DBP / display width=5;
define Hypertensive / computed "Hypertensive?" width=13;
compute Hypertensive / character length=3;
if Gender = 'F' and (SBP gt 138 or DBP gt 88)
then Hypertensive = 'Yes';
else Hypertensive='No';
if Gender = 'M' and
(SBP gt 140 or DBP gt 90)
then Hypertensive = 'Yes';
else Hypertensive = 'No';
endcomp;
run;
quit;

#Output:


#Explanation:

                In the above program we are trying to check whether the person is Hypertensive or not.  For that we need an output based on the requirements which is explained in the problem statement. In the solution we use a statement called DEFINE which is used to specify the usage for each variable. Learning how to control whether to produce a detail listing or a summary report and what
statistics to produce leads you to the DEFINE statement. The DEFINE option DISPLAY is an instruction to produce a detailed listing of all observations. Besides defining the usage as DISPLAY, the DEFINE statement also carry a GROUP option when we need to club the data.

               Another import thing in the above program is COMPUTE. One powerful feature of PROC REPORT is its ability to compute new variables. This makes PROC REPORT somewhat unique among SAS procedures. We can use the compute statements to create a COMPUTE block where we can define the new variables inside the block. Here we compute whether he patient is Hypertensive or not based on the SBP and DB values using the IF else statements which we already learned. Also, we used quit statement to stop the procedure, otherwise it wont stop.

No comments:

Post a Comment