Contributor
Posts: 21

Unable to do calculation within my dataset

My data is in the code below:-

data cody.emfpredict;

input V R E;

datalines;

10 3 50

5 9 45

;

run;

I want to calculate a new variable emf, where emf = 1.45*V + (R/E)*V**3-125. So that the new column is created along with the calculated result (using inputs).

I'm able to do the calculation if I copy the date by using data and set statement.

But how can I add new column to the empfredict data and get the calculated results?

Super Contributor
Posts: 276

Re: Unable to do calculation within my dataset

Hi Sridhar,

Is this are you looking for ??

data emfpredict;

input V R E;

emf = 1.45*V + (R/E)*V**3-125;

datalines;

10 3 50

5 9 45

;

run;

PRoc print;

run;

Regards,

Sanjeev.K

Contributor
Posts: 21

Re: Unable to do calculation within my dataset

Thanks Sanjeev. Appreciate your prompt response.

I tried providing the formula but made a mistake. (i.e. I had put the formula/calc after data lines)

This code solves by problem.

One small question. What if I want to keep the emfpredict as such and show the new variable and calculation only in the output? (so that the original data is same).

Super Contributor
Posts: 276

Re: Unable to do calculation within my dataset

Hi,

IF you want to calculate new variable just for displaying purpose and to not effect the original dataset,In that case you can use Proc Reprot.

Here we Go,

data emfpredict;

input V R E;

datalines;

10 3 50

5 9 45

;

run;

Proc Report data =emfpredict;

Columns V R E emf;

Define V /Format=10.;

Define R/Format=10.;

Define E/Format=10.;

Define emf/Computed Format=10.2;

Compute Emf;

emf = 1.45*V + (R/E)*V**3-125;

Endcomp;

Run;

Regards,

Sanjeev.K

Discussion stats
• 3 replies
• 217 views
• 2 likes
• 2 in conversation