athresh
athresh

Reputation: 553

IN clause in SAS

I have the below dataset

data a;
input id stat$;
datalines;
10 a
20 a
10 t
40 t
;
run;  

I am writing the below macro

%macro ath(inp);
data _null_;
set a (where=(id=&inp);
----if any one of the status of ID is 'a' then put 'valid';
else put 'invalid';----
%mend;

I am a beginner in SAS. Please help me in writing the syntax for - if any one of the status of ID is 'a' then put 'valid'; else put 'invalid'

Upvotes: 0

Views: 693

Answers (2)

Zfunk
Zfunk

Reputation: 1193

As you have a where statement here, surely all the id's you select are going to be valid? I.e. you are selecting all the rows where id = &inp, so if your variable &inp = 'a' then all rows of the new dataset will be valid. Sorry if I have missed something here!

Upvotes: 0

Hong Ooi
Hong Ooi

Reputation: 57686

It looks like you want to scan over all (selected) rows in the input data, and test whether any of them has ID = 'a'. You don't do this with an IN clause; that's for testing against a set of values for each row, as opposed to testing against one value for all rows.

data _null_;
    set a (where=(id = &inp);
    if id = 'a' then do;
        put 'valid';
        stop;
    end;
run;

Upvotes: 2

Related Questions