BookmarkSubscribeRSS Feed
Tadeu1
Fluorite | Level 6

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);
 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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