Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- PROC REPORT

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-25-2013 05:15 PM

Below is my code. The output is giving me blanks for the two computed columns BMI_Cat and Ab_Change and I cannot figure out why.

proc report data=combine nowd headskip missing;

column Pt_Id Dosedate Age Sex Race Wt_Cat BMI BMI_Cat Result1 Result2 Ab_Change;

define Pt_Id / order 'Patient' width=7;

define Dosedate / width=8 format=mmddyy8.;

define Age / 'Age' width=3;

define Sex / width=6;

define Race / width=9;

define Wt_Cat / 'Weight Category' width=16;

define Result1 / 'Analyte Result 1' width=8 format=8.2;

define Result2 / 'Analyte Result 2' width=8 format=8.2;

define Ab_Change / computed 'Absolute Change';

define BMI / width=3;

define BMI_Cat / computed 'BMI Category' width=10;

compute BMI_Cat / character length=10;

if BMI lt 18.5 then BMI_Cat = 'Underweight';

else if BMI gt 18.5 and BMI lt 25 then BMI_Cat = 'Normal';

else if BMI gt 25 and BMI lt 30 then BMI_Cat = 'Overweight';

else if BMI gt 30 then BMI_Cat = 'Obese';

endcomp;

compute Ab_Change;

Ab_change = Result1 - Result2;

endcomp;

run;

Accepted Solutions

Solution

02-25-2013
05:47 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-25-2013 05:47 PM

Hi:

You don't provide a USAGE for the BMI variable so if it is a numeric variable, then it is using the SUM statistic by default. And the same thing would be true of Result1 and Result2. Without a usage in the DEFINE statement, you get the SUM statistic for numeric variables by default.

The first method to fix your problem is to take the defaults for numeric variables in your DEFINE statement and alter your COMPUTE blocks. This means that in a COMPUTE block you have to use the compound reference of * varname.statisticname* in the COMPUTE block. So BMI.SUM and RESULT1.SUM and RESULT2.SUM:

**compute BMI_Cat / character length=10;**

** if BMI.sum le 18.5 then BMI_Cat = 'Underweight';**

** else if BMI.sum gt 18.5 and BMI.sum le 25 then BMI_Cat = 'Normal';**

** else if BMI.sum gt 25 and BMI .sum le 30 then BMI_Cat = 'Overweight';**

** else if BMI.sum gt 30 then BMI_Cat = 'Obese';**

** endcomp;**

** compute Ab_Change;**

** Ab_change = Result1.sum - Result2.sum;**

** endcomp;**

This is what you would need to do with the current DEFINE statements that you have. The upside of this approach is that if you want to add subtotals or grand totals, you can do that. But since you are getting a detail report (one row for every PT_ID you may not want a grand total summary line).

And, there is an alternative. The second approach is to keep your COMPUTE blocks the way they are and alter the DEFINE statements to specify a non-statistic usage:

** define Result1 / DISPLAY 'Analyte Result 1' width=8 format=8.2;**

** define Result2 / DISPLAY 'Analyte Result 2' width=8 format=8.2;**

** define BMI / DISPLAY width=3;**

The upside of this approach is that you don't have to change the COMPUTE block. The downside of this approach is that if you EVER want to get grand totals or subtotals, you'll have to get rid of DISPLAY (and either take the default or change the statistic), and then you're back to needing to change your COMPUTE block.

cynthia

All Replies

Solution

02-25-2013
05:47 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-25-2013 05:47 PM

Hi:

You don't provide a USAGE for the BMI variable so if it is a numeric variable, then it is using the SUM statistic by default. And the same thing would be true of Result1 and Result2. Without a usage in the DEFINE statement, you get the SUM statistic for numeric variables by default.

The first method to fix your problem is to take the defaults for numeric variables in your DEFINE statement and alter your COMPUTE blocks. This means that in a COMPUTE block you have to use the compound reference of * varname.statisticname* in the COMPUTE block. So BMI.SUM and RESULT1.SUM and RESULT2.SUM:

**compute BMI_Cat / character length=10;**

** if BMI.sum le 18.5 then BMI_Cat = 'Underweight';**

** else if BMI.sum gt 18.5 and BMI.sum le 25 then BMI_Cat = 'Normal';**

** else if BMI.sum gt 25 and BMI .sum le 30 then BMI_Cat = 'Overweight';**

** else if BMI.sum gt 30 then BMI_Cat = 'Obese';**

** endcomp;**

** compute Ab_Change;**

** Ab_change = Result1.sum - Result2.sum;**

** endcomp;**

This is what you would need to do with the current DEFINE statements that you have. The upside of this approach is that if you want to add subtotals or grand totals, you can do that. But since you are getting a detail report (one row for every PT_ID you may not want a grand total summary line).

And, there is an alternative. The second approach is to keep your COMPUTE blocks the way they are and alter the DEFINE statements to specify a non-statistic usage:

** define Result1 / DISPLAY 'Analyte Result 1' width=8 format=8.2;**

** define Result2 / DISPLAY 'Analyte Result 2' width=8 format=8.2;**

** define BMI / DISPLAY width=3;**

The upside of this approach is that you don't have to change the COMPUTE block. The downside of this approach is that if you EVER want to get grand totals or subtotals, you'll have to get rid of DISPLAY (and either take the default or change the statistic), and then you're back to needing to change your COMPUTE block.

cynthia

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-25-2013 06:11 PM

Thank you. That makes perfect sense.

Crystal