BookmarkSubscribeRSS Feed
karns
Calcite | Level 5

Hello everyone,

I am having an issue selecting at subset of observations. I want to select based on the condition that each participant for each event, the subset have 3 or more values (>= .02) of a particular variable (VAR).

For example,

PID     Event     VAR

1923     1          0

1923     1          .02

1923     1          .03

1923     1          .04

1923     1          .002

1923     1          0

2003     1          0

2003     1          .02

2003     1          .06

2003     1          .07

2003     1          .003

2003     1          0


So in this example, both participants would be selected because they have 3 or more observations in VAR that are >= .02. Please note that each participant has multiple events so I need to check each event for each participant.


Any direction would be greatly appreciated!

Thank you!

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Something along these lines:

data have;
  attrib PID Event VAR format=best.;
  input pid event var;
datalines;
1923     1          0

1923     1          .02

1923     1          .03

1923     1          .04

1923     1          .002

1923     1          0
;
run;


proc sql;
  create table WANT as
  select  *
  from  (select PID,EVENT,VAR,case when VAR > 0.02 then "Y" else "N" end as FLAG from HAVE)
  group by PID,EVENT
  having  COUNT(FLAG)>1;
quit;

stat_sas
Ammonite | Level 13

data have;
input PID     Event     VAR;
datalines;
1923     1          0
1923     1         .02
1923     1         .03
1923     1         .04
1923     1         .002
1923     1          0
2003     1          0
2003     1         .02
2003     1         .06
2003     1         .07
2003     1         .003
2003     1          0
;

proc sql;
select * from have
group by pid,event
having sum(var>=0.02)>=3;
quit;

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
  • 2 replies
  • 390 views
  • 0 likes
  • 3 in conversation