subsetting 'read all into'

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

subsetting 'read all into'

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


Accepted Solutions
Solution
‎02-17-2013 08:00 PM
Super User
Super User
Posts: 6,502

Re: subsetting 'read all into'

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;

View solution in original post


All Replies
PROC Star
Posts: 7,364

Re: subsetting 'read all into'

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.

Super User
Super User
Posts: 6,502

Re: subsetting 'read all into'

Dataset options go inside of parenthesis right after the dataset name.

Replace reference to Beetles with

Beetles ( where= ( type=0 ) )


Occasional Contributor
Posts: 8

Re: subsetting 'read all into'

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;

Solution
‎02-17-2013 08:00 PM
Super User
Super User
Posts: 6,502

Re: subsetting 'read all into'

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;

Occasional Contributor
Posts: 8

Re: subsetting 'read all into'

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!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 250 views
  • 0 likes
  • 3 in conversation