Hi,
I am trying to find a number of observations in a given dataset (after sub-setting if where condition is provided) using proc iml.
The where option present in "use, read and other" statements in proc iml does not allow to use "Mnemomic" operators (for ex: eq, ne, ge and so on).
I have tried to use the "where" as a dataset option as below
data one;
input v2;
cards;
1
2
3
4
45
56
;
run;
proc iml;
use one (where = (v2 le 40)) nobs a var _all_;
print a;
close one;
quit;
I am getting the value of a as "6".
Is there any way to sub-set the dataset (where statement with "Mnemomic" operators? and get the number of observations in the resulting dataset?
Thanks in Advance,
Venkat.
The USE statement does not read data. It merely opens the data set and examines the characteristics (type, length,...) of the variables.
When you apply WHERE clause to filter the data, the only way to know how many observations pass through the filter is to actually read the data.
proc iml;
use one (where = (v2 le 40));
read all var {"v2"};
close one;
n = nrow(v2);
print n;
Hi Rick,
Here, variable name "V2" is hard coded. Is there any way to generalize this?
If, the dataset is huge then read statement is taking much time to convert the dataset into a matrix.
Is there any way to get a name of any of the variable from the input dataset and use it in both "read" and "nrow"?
Thanks,
Venkat.
use the CONTENTS function to get the names of variables. Then read any variable, such as the first
proc iml;
use sashelp.class (where = (age le 15));
varNames = contents();
print varNames;
read all var (varNames[1]) into X;
close one;
n = nrow(X);
print n;
Thank you very much Rick...Its working...
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.