D. Studer
D. Studer

Reputation: 1875

compute variable after datalines

I have the following dataset (fictional data).

DATA test;
    INPUT name $ age height weight;
    DATALINES;
Peter 20 1.70 80
Hans 30 1.72 75
Tina 25 1.67 65
Luisa 10 1.20 50
;
RUN;

How can I compute a new variable "bmi" (weight / height^2) directly after the end of the DATALINE-command? Unfortunately in my SAS-book all the examples are with DATA ... INFILE= instead of using DATALINES.

PROC PRINT 
    DATA = test;
    TITLE 'Fictional Data';
RUN;

Upvotes: 2

Views: 202

Answers (1)

Richard
Richard

Reputation: 27508

Datalines appears at the end of the data step. Your computation statements should be placed before datalines, after the input

INPUT name $ age height weight;
bmi = weight / height**2;
DATALINES;
… 

Upvotes: 2

Related Questions