BookmarkSubscribeRSS Feed
tmjeffer
Calcite | Level 5

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;

 

10 REPLIES 10
Reeza
Super User

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;

 


 

 

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


Reeza
Super User

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.



 

tmjeffer
Calcite | Level 5

Listing of Prob2

 

Obs ID Height Weight SBP DBP Wtkg HtCm AveBP HtPolynomial123
001681501107068.182172.7283.333480896.0
0027324015090109.091185.42110.000594183.5
003621011208045.909157.4893.333365180.0

 

 

 

/*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;

 

 

 

Reeza
Super User
I'm assuming this works now?
tmjeffer
Calcite | Level 5
Yes it does. Thanks for all your help!
heatherjae15
Obsidian | Level 7

Hello,

 

I need to convert inches to cm in some of my data, it is a mixed bag of inches and cms. 

my variables

comor_9hgtunit_decode = says whether it is in inches or cm

comor_9hgtunit  gives 1 for cm and 2 for inches

comor_9hgt  = measurements in inches or cms

 

Here is how I approached it.

 

data demo2;
set mergedata;
If comor_9htunit then do;
height_cm = comor_9ht/2.54;
end;
else do;
height_cm =comor_9ht;
end;
run;

 

I am getting the error code WARNING: The data set WORK.DEMO2 may be incomplete. When this
step was stopped there were 0 observations and 3
variables.

 

 

ScottBass
Rhodochrosite | Level 12

If comor_9htunit then do;

 

Is this statement true, or false, when comor_9htunit=1?

Is this statement true, or false, when comor_9htunit=2?

 

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Reeza
Super User
I posted a fairly detailed explanation of the issue in one of your other posts. Please DO NOT ask the same question in multiple places and this thread is a year + old.

Go check your other questions and posts and you'll find the correct answer and explanation.
https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-values-rules-in-other-co...
heatherjae15
Obsidian | Level 7
Thank you

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 10 replies
  • 4835 views
  • 2 likes
  • 4 in conversation