Reputation: 237
I know that this is a very basic question, but I really am having trouble.
I wrote the following code and all I want to do is to read the data correctly, but I cannot find a way to instruct SAS to read the BMI.
There are two things I want to do.
1), Have SAS store the entire number including all the decimals. 2), when printed, I would like to approximate the number to two decimal points.
data HW02EX01;
input Patient 1-2 Weight 5-7 Height 9-10 Age 13-14 BMI 17-26 Smoking $ 29-40 Asthma $ 45-48;
cards;
14 167 70 65 23.9593878 never no
run;
Note: I left only the first observation since the display becomes really ugly and wearisome to edit by hand.
Upvotes: 0
Views: 147
Reputation: 21274
See the comments in the code, specifically the usage of LENGTH
, FORMAT
and INFORMAT
statements to control the input and output appearance of data.
data HW02EX01;
*specify the length of the variables;
length patient $8. weight height age bmi 8. smoking asthma $8.;
*specify the informats of the variables;
*an informat is does the variable look like when trying to read it in;
informat patient $8. weight height age bmi best32.;
*formats control how infomraiton is displayed in output/tables;
format bmi 32.2 weight height age 12.;
input Patient $ Weight Height Age BMI Smoking Asthma ;
cards;
14 167 70 65 23.9593878 never no
;
run;
Upvotes: 1
Reputation: 31
friend.
Maybe it could be useful the following code:
data HW02EX01_;
input Patient Weight Height Age BMI Smoking : $20. Asthma $10.;
format BMI 32.2;
cards;
14 167 70 65 23.9593878 never no
;
By way of comment, I would like to indicate some details:
I hope it will be useful.
Upvotes: 2