Hello, I have the code below. However, I'd only like X to contain observations where type=0. When I put a 'where' conditional on my 'use' statement, I get the error: No data set is currently open for input. Here's the code for that:
filename myfile 'T5_5_FBEETLES.dat';
data Beetles;
infile myfile;
input num type x1 x2 x3 x4;
proc iml;
use Beetles where type=0;
read all var{x1 x2 x3 x4} into X;
print X;
run;
error: No data set is currently open for input.
I also tried adding the 'where' on the 'read all' statement, but I get the error on 'type': Expecting a (. Here's the code for that:
dm "out; clear; log; clear";
filename myfile 'T5_5_FBEETLES.dat';
data Beetles;
infile myfile;
input num type x1 x2 x3 x4;
proc iml;
use Beetles;
read all var{x1 x2 x3 x4} into X where type=0;
print X;
run;
Error: Expecting a (.
[just edited my post so that it's more clear]
Message was edited by: egg man
Works for me. IML doesn't like the RUN statement.
data Beetles;
input num type x1 x2 x3 x4;
cards;
5 0 1 2 3 4
6 1 2 3 4 5
run;
proc iml;
use Beetles (where= (type=0)) ;
read all var{x1 x2 x3 x4} into X;
print X;
quit;
You can include a where dataset option with your 'use' statement. You didn't include anything in your code showing a where clause, or the syntax error, thus I'm not sure what you tried.
Dataset options go inside of parenthesis right after the dataset name.
Replace reference to Beetles with
Beetles ( where= ( type=0 ) )
I just tried that but I'm getting the error: Matrix X has not been set to a value
dm "out; clear; log; clear";
filename myfile 'T5_5_FBEETLES.dat';
data Beetles;
infile myfile;
input num type x1 x2 x3 x4;
proc iml;
use Beetles (where= (type=0));
read all var{x1 x2 x3 x4} into X;
print X;
run;
Works for me. IML doesn't like the RUN statement.
data Beetles;
input num type x1 x2 x3 x4;
cards;
5 0 1 2 3 4
6 1 2 3 4 5
run;
proc iml;
use Beetles (where= (type=0)) ;
read all var{x1 x2 x3 x4} into X;
print X;
quit;
Problem was that I didn't have any observations of type=0. I thought it was a 0 or 1 variable but was a 1 or 2. Thanks for the help!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.