BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASFNG
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

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

SASFNG
Calcite | Level 5

Thank you. That makes perfect sense.

Crystal

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 987 views
  • 0 likes
  • 2 in conversation