Reputation: 3
I am trying to learn some basic DS2 programming by writing a program that calculates BMI. I have written a program but I am getting 'ERROR: Line 47: Attempt to obtain a value from a void expression.'. What am I doing wrong?
Here is my program:
proc ds2;
data _null_;
dcl double bmi;
method bmi_calc(double height, double weight);
dcl double bmi;
bmi = weight/(height * height);
end;
method init();
weight = 70.5;
height = 1.68;
end;
method run();
bmi = bmi_calc(height, weight);
put 'BMI IS: ' bmi;
end;
method term();
put bmi;
end;
enddata;
run;
quit;
Upvotes: 0
Views: 152
Reputation: 12909
You need to do two things with custom methods in ds2:
For example, this method returns the value 10
.
method foo() returns double;
return 10;
end;
To make your method work, you simply need to state what type of variable you are returning and then return that value.
method bmi_calc(double height, double weight) returns double;
dcl double bmi;
bmi = weight/(height * height);
return bmi;
end;
Upvotes: 0