0

I am using proc iml to manipulate the dataset. I am using if statement to check two conditions

if the value is -7 or -8, I wrote this code below but the if statement is giving me errors because i am specifying the or condition incorrectly. Please help.

Proc iml;
use Adult;
read all var {AB34 AC7 AB63 SRSEX RACECEN  } into Var1 ;

use Adultf;
read all var {AB34_x AC7_X AB63_X} into VarMiss ;

Var2 = Var1;
HrtIss_X = VarMiss[,1];

DO i=1 to nrow(Var2);
    if HrtIss_X[i,1] = -7 or HrtIss_X[i,1] = -8  then Var2[i,1]=.;
end;
Joe
  • 62,789
  • 6
  • 49
  • 67
bison2178
  • 747
  • 1
  • 8
  • 22

1 Answers1

0

First, you need to use | instead of OR (and & instead of AND). Annoying, I know, but IML only works with those.

Second, you're not doing that the most efficient (and the most IMLy) way possible. Use LOC.

Proc iml;
use sashelp.class;
read all var {name sex } into Var1 ;

read all var {age} into VarMiss ;

Var2 = Var1;
HrtIss_X = VarMiss[,1];
DO i=1 to nrow(Var2);
    if (HrtIss_X[i,1] = 13) | (HrtIss_X[i,1] = 14)  then Var2[i,1]=' ';
end;
print var2;
*Better way to do this;
var2[loc(HrtIss_X = 13|HrtIss_X=14),2]=' ';
print var2;
quit;

This should be more efficient and is a more matrix oriented approach. LOC gets you the rows that match HrtIss_X equals whatever values, and returns their row numbers, which you can pass to var2 to subset it.

Joe
  • 62,789
  • 6
  • 49
  • 67