BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eggman2001
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

5 REPLIES 5
art297
Opal | Level 21

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.

Tom
Super User Tom
Super User

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

Replace reference to Beetles with

Beetles ( where= ( type=0 ) )


eggman2001
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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;

eggman2001
Calcite | Level 5

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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