Solved
Contributor
Posts: 39

# Implementing the fomula in sas

[ Edited ]

Hi all,

Here I have tried with the formula but I get a partial output.

By using the sample data set please proceed with the formula code.

``````data have;
input age bmi diab diab_bln\$ alt ast plat albu;
cards;
61.3	25.43252595	1	no	22	18	3.29	3.2
74.4	30.04768905	2	yes	23	17	2.29	4.2
70.4	24.26987561	22	yes	19	21	2.98	4.4
56.4	38.17497196	5	no	33	25	1.97	4.4
75.4	40.96495221	2	yes	49	103	1.84	3.2
69.4	21.60288505	8	no	16	15	2.64	4.1
run;
proc print;
run;/*Apart from 2 and 22, whatever the value on diab column it should be NO in diab_bln column*/``````
``````data want;
set have;
Score =
-1.675+(0.037*age)+(0.094*bmi)+(1.13*(diab_bln = ifn(diab_bln='yes')* 1)) +
(0.99*AST/ALT) - (0.013*plat) - (0.66*albu);
run;
proc print;
run;``````

This is the exact formula:

NAFLD Score = -1.675 + (0.037*age[years]) + (0.094*BMI) + (1.13*diab [yes = 1, no = 0]) + (0.99*AST/ALT ratio) – (0.013*platelet count [×109/L]) – (0.66*albumin)

You may get any answer by using the formula but

To cross check the result, The given link will use to verify the score value.

https://qxmd.com/calculate/calculator_341/nafld-fibrosis-score

Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 10,570

## Re: Implementing the fomula in sas

And you may consider breaking up the formula into separate lines so that the single blocks are easier to read:

``````data want;
set have;
Score =
-1.675 +
(0.037*age) +
(0.094*bmi) +
(1.13*(diab_bln = 'yes')) +
(0.99*AST/ALT) -
(0.013*plat) -
(0.66*albu)
;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Super User
Posts: 10,570

## Re: Implementing the fomula in sas

Hint: always do a test run of your example data code, to make sure that it works (see the infile statement I had to add)

You are overcomplicating the check for yes/no, try this instead:

``````data have;
infile cards dlm='09'x;
input age bmi diab diab_bln\$ alt ast plat albu;
cards;
61.3	25.43252595	1	no	22	18	3.29	3.2
74.4	30.04768905	2	yes	23	17	2.29	4.2
70.4	24.26987561	22	yes	19	21	2.98	4.4
56.4	38.17497196	5	no	33	25	1.97	4.4
75.4	40.96495221	2	yes	49	103	1.84	3.2
69.4	21.60288505	8	no	16	15	2.64	4.1
run;

data want;
set have;
Score =
-1.675+(0.037*age)+(0.094*bmi)+(1.13*(diab_bln = 'yes')) +
(0.99*AST/ALT) - (0.013*plat) - (0.66*albu);
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
3 weeks ago
Super User
Posts: 10,570

## Re: Implementing the fomula in sas

And you may consider breaking up the formula into separate lines so that the single blocks are easier to read:

``````data want;
set have;
Score =
-1.675 +
(0.037*age) +
(0.094*bmi) +
(1.13*(diab_bln = 'yes')) +
(0.99*AST/ALT) -
(0.013*plat) -
(0.66*albu)
;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.