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

Hi,

I have a table like the following :

NAMEALERT_DATE
bob2010-12-10
nicolas2013-06-20
nicolas2013-06-30
bob2012-10-10
william2013-07-01
guy2011-11-10
william2013-07-02
julie2013-07-10
julie2013-07-13

I would like to write a query so that I only keep the records where the first alert for each name was between the 2013-05-01 and 2013-07-05. So I would like to kill all the name that had an alert that was before 2013-05-01 and all the records where the first alert was after 2013-07-05. For each of those name I would like to keep only the first alert.

So the end result would be :

NameALERT_DATE
nicolas2013-06-20
william2013-07-01

Could you please help me write that query?

Thank you for your help and time.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

It's pretty easy if you first sort by name and alert_date.

Then, a simple datastep works

data whatever;

     set whatever;

     by name;

     if first.name and alert_date>'01MAY13'd and alert_date<'05JUL13'd; /* Assumes alert_date is numeric date */

run;

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

It's pretty easy if you first sort by name and alert_date.

Then, a simple datastep works

data whatever;

     set whatever;

     by name;

     if first.name and alert_date>'01MAY13'd and alert_date<'05JUL13'd; /* Assumes alert_date is numeric date */

run;

--
Paige Miller
nicnad
Fluorite | Level 6

Works like a charm and makes much sense.

Thank you very much for your help!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 773 views
  • 0 likes
  • 2 in conversation