New Contributor
Posts: 4

Compute 4 new variables

I cannot figure out where I am going wrong in the problem below. I know it's something I'm overlooking.

/*2 Given the programs here, add the necessary statements to compute the four new variables. */

*a /Weight in kilograms (1kg = 2.2 pounds). Name this variable WtKg/;

*b /Height in centimenters (1 inch = 2.54 cm). Name this variable HtCm. */ ;

*c /Average blood pressure (call it AveBP)equal to the diastolic blood pressure plus one-third difference of the systolic blood pressure minus the diastolic blood pressure. */;

*d /A variable (call it HtPolynomial) equal to 2 times the height squared plus 1.5 times the height cubed. */;

DATA Prob2;

INPUT ID \$

Height /* in inches */

Weight /* in pounds */

SBP /* systolic B P */

DBP /* diastolic B P */;

Wtkg = Weight/2.2;

HtCm = Height/2.54;

AveBP = DBP + 1/3SBP - DBP;

HtPolynomial = 2 *Height**2 + 1.5 *Height**3;

DATALINES;

001 68 150 110 70

002 73 240 150 90

003 62 101 120 80

;

TITLE "Listing of Prob2";

PROC PRINT DATA = Prob2;

Run;

Super User
Posts: 22,874

Re: Compute 4 new variables

[ Edited ]

AveBP = DBP + 1/3SBP - DBP;

That's probably not what you want, and it's where SAS generated the error.

Second, review how you're converting height. Would you expect height in cm to be lareger than height in inches? Your conversion is likely backwards.

@tmjeffer wrote:

I cannot figure out where I am going wrong in the problem below. I know it's something I'm overlooking.

/*2 Given the programs here, add the necessary statements to compute the four new variables. */

*a /Weight in kilograms (1kg = 2.2 pounds). Name this variable WtKg/;

*b /Height in centimenters (1 inch = 2.54 cm). Name this variable HtCm. */ ;

*c /Average blood pressure (call it AveBP)equal to the diastolic blood pressure plus one-third difference of the systolic blood pressure minus the diastolic blood pressure. */;

*d /A variable (call it HtPolynomial) equal to 2 times the height squared plus 1.5 times the height cubed. */;

DATA Prob2;

INPUT ID \$

Height /* in inches */

Weight /* in pounds */

SBP /* systolic B P */

DBP /* diastolic B P */;

Wtkg = Weight/2.2;

HtCm = Height/2.54;

AveBP = DBP + 1/3SBP - DBP;

HtPolynomial = 2 *Height**2 + 1.5 *Height**3;

DATALINES;

001 68 150 110 70

002 73 240 150 90

003 62 101 120 80

;

TITLE "Listing of Prob2";

PROC PRINT DATA = Prob2;

Run;

New Contributor
Posts: 4

Re: Compute 4 new variables

I put parentheses around (SBP -DBP) First and couldn’t get it to read either.

Super User
Posts: 22,874

Re: Compute 4 new variables

Post your new code and log, and remember order of operations so make sure you have parenthesis where you need them.

@tmjeffer wrote:
I put parentheses around (SBP -DBP) First and couldn’t get it to read either.

New Contributor
Posts: 4

Re: Compute 4 new variables

 Listing of Prob2

Obs ID Height Weight SBP DBP Wtkg HtCm AveBP HtPolynomial123
 001 68 150 110 70 68.182 172.72 83.333 480896 002 73 240 150 90 109.091 185.42 110 594184 003 62 101 120 80 45.909 157.48 93.333 365180

/*2 Given the programs here, add the necessary statements to compute the four new variables. */

*a /Weight in kilograms (1kg = 2.2 pounds). Name this variable WtKg/;

*b /Height in centimenters (1 inch = 2.54 cm). Name this variable HtCm. */ ;

*c /Average blood pressure (call it AveBP)equal to the diastolic blood pressure plus one-third difference of the systolic blood pressure minus the diastolic blood pressure. */;

*d /A variable (call it HtPolynomial) equal to 2 times the height squared plus 1.5 times the height cubed. */;

DATA Prob2;

INPUT ID \$

Height /* in inches */

Weight /* in pounds */

SBP /* systolic B P */

DBP /* diastolic B P */;

Wtkg = Weight/2.2;

HtCm = Height*2.54;

AveBP = DBP + 1/3 *(SBP - DBP);

HtPolynomial = 2 * (Height)**2 + 1.5 * (Height)**3;

DATALINES;

001 68 150 110 70

002 73 240 150 90

003 62 101 120 80

;

TITLE "Listing of Prob2";

PROC PRINT DATA = Prob2;

Run;

Super User
Posts: 22,874

Re: Compute 4 new variables

I'm assuming this works now?
New Contributor
Posts: 4

Re: Compute 4 new variables

Yes it does. Thanks for all your help!
Discussion stats
• 6 replies
• 94 views
• 0 likes
• 2 in conversation