Help using Base SAS procedures

Where statement with IN operator

Reply
New Contributor
Posts: 3

Where statement with IN operator

Hi

Actually I want to sub set my data with the following program

data final.abc;
set abc;
where date = '30Dec2010" d and customerNo in (select custno. from salesdata);
run;

data set abc and and data set salesdata both exist in as a temporary data set.
I want to sub set the data not only by date (a variable in dataset abc) but also by CustomerNo( also a variable in data set abc) by setting its value equal to Custno. ( a variable in another dataset salesdata).

Can somebody please check the syntax for sas, as I am unable to run this command.

regards
Mars
Super Contributor
Posts: 281

Re: Where statement with IN operator

SELECT clause will not work in a Data step.

If you want to use the SELECT clause, you have to do this in PROC SQL.
Super Contributor
Super Contributor
Posts: 3,174

Re: Where statement with IN operator

The SAS PROC SQL documentation has examples for generating a macro variable data-string for a WHERE IN () as you have suggested.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

generate where statement in string using proc sql select into site:sas.com
Super Contributor
Super Contributor
Posts: 365

Re: Where statement with IN operator

Hello Mars,

You need something like this:
[pre]
proc SQL;
create table final.abc as
select a.*,b.* /* list all variables you need from two datasets */
from abc as a, salesdata as b
where a.date='30Dec2010'd and a.customerNo=b.Custno
;quit;
[/pre]
Sincerely,
SPR
Ask a Question
Discussion stats
  • 3 replies
  • 177 views
  • 0 likes
  • 4 in conversation