BookmarkSubscribeRSS Feed
Venkibhu1
Calcite | Level 5

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.

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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;
Venkibhu1
Calcite | Level 5

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.

Rick_SAS
SAS Super FREQ

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;
Venkibhu1
Calcite | Level 5

Thank you very much Rick...Its working...

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

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
  • 4 replies
  • 913 views
  • 0 likes
  • 2 in conversation