BookmarkSubscribeRSS Feed
Tadeu1
Calcite | Level 5

Dear,

I woud like criate a PESO variable string but I get an Error(1): 

 

Also I woul like insert an new extra row like:

Carlos M 62 72  75

 

Thanks in advance

==================================================

proc iml;
tClass=TableCreateFromDataSet ("Sashelp", "Class");
call TablePrint(tClass);

Y=TableGetVarData (tClass, {"Weight" "Height"});
wt=Y[,1];
ht=Y[,2];
BMI=wt/ht##2 * 703;


if (BMI>=18.5) & (BMI<=24.9) then PESO="Normal";
if (BMI>=25.0) & (BMI<=29.9) then PESO="Sobrepeso";
if (BMI>=30.0) & (BMI<=39.9) then PESO="Obesidade";
if (BMI>=40.0) then PESO="Obesidade Grave";

quit;

 

call TableAddVar(tClass, "BMI", BMI);
call TableAddVar(tClass, "PESO", PESO);

2 REPLIES 2
Ksharp
Super User

Better post it at IML forum. and calling out @Rick_SAS 

Rick_SAS
SAS Super FREQ

The reason your program is not working is that PESO must be a vector with the same number of elements as the BMI variable. There are two ways to do this:

1. Define a format and use the format to recode the BMI vector.

2. Use the BIN function in IML to classify each BMI value into a category.

The program below shows the second method:

 

proc iml;
tClass=TableCreateFromDataSet ("Sashelp", "Class");
*call TablePrint(tClass);

Y=TableGetVarData (tClass, {"Weight" "Height"});
wt=Y[,1];
ht=Y[,2];
BMI=wt/ht##2 * 703;

/* allocate vector that is the same length as the data */
catIdx = bin(BMI, cutpts);
/* set up cut points */
category = {'Abaixo do Peso' 'Normal' 'Sobrepeso' 'Obesidade' 'Obesidade Grave'};
cutpts = {.M               18.5     25           30          40               .I};
PESO = category[ catIdx ];

call TableAddVar(tClass, "BMI", BMI);
call TableAddVar(tClass, "PESO", PESO);
call TablePrint(tClass);
 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 451 views
  • 1 like
  • 3 in conversation