Sorry. Change it into the following
data have;
length from to $ 40;
set temp ;
run;
But I only got zero obs. that means all these identip cg are linked by the level which has less than 3 count .
Do you want both X and Y to have fewer than 3 occurrences? Or both? Or the combination of X and Y to appear less than 2 times?
data have;
input id x $ y $;
cards;
1 2 2
2 6 2
3 1 3
4 3 4
5 3 3
6 5 3
7 1 3
8 5 3
9 4 1
10 6 1
11 3 4
12 1 4
13 5 4
14 7 2
15 3 4
;
proc sql ;
create table test1 as
select *,count(*) as n_xy
, (n_x <3 or n_y <3) as rule1
, (n_x <3 and n_y <3) as rule2
, (calculated n_xy<3) as rule3
from (select *,count(*) as n_y
from (select *,count(*) as n_x from have group by x) a
group by y) b
group by x,y
order by id
;
quit;
Obs id x y n_x n_y n_xy rule1 rule2 rule3 1 1 2 2 1 3 1 1 0 1 2 2 6 2 2 3 1 1 0 1 3 3 1 3 3 5 2 0 0 1 4 4 3 4 4 5 3 0 0 0 5 5 3 3 4 5 1 0 0 1 6 6 5 3 3 5 2 0 0 1 7 7 1 3 3 5 2 0 0 1 8 8 5 3 3 5 2 0 0 1 9 9 4 1 1 2 1 1 1 1 10 10 6 1 2 2 1 1 1 1 11 11 3 4 4 5 3 0 0 0 12 12 1 4 3 5 1 0 0 1 13 13 5 4 3 5 1 0 0 1 14 14 7 2 1 3 1 1 0 1 15 15 3 4 4 5 3 0 0 0
So which sets of records do you want to keep those based on RULE1 , RULE2 , RULE3 or some other value?
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: