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-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!

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.

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
  • 616 views
  • 0 likes
  • 2 in conversation