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);
Better post it at IML forum. and calling out @Rick_SAS
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);
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.