Hi,
I have a table like the following :
| NAME | ALERT_DATE |
|---|---|
| bob | 2010-12-10 |
| nicolas | 2013-06-20 |
| nicolas | 2013-06-30 |
| bob | 2012-10-10 |
| william | 2013-07-01 |
| guy | 2011-11-10 |
| william | 2013-07-02 |
| julie | 2013-07-10 |
| julie | 2013-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 :
| Name | ALERT_DATE |
|---|---|
| nicolas | 2013-06-20 |
| william | 2013-07-01 |
Could you please help me write that query?
Thank you for your help and time.
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;
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;
Works like a charm and makes much sense.
Thank you very much for your help!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.