Help using Base SAS procedures

Determine if the first occurence of a record was during a given period

Accepted Solution Solved
Reply
Regular Contributor
Posts: 186
Accepted Solution

Determine if the first occurence of a record was during a given period

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.


Accepted Solutions
Solution
‎07-19-2013 12:34 PM
Trusted Advisor
Posts: 1,908

Re: Determine if the first occurence of a record was during a given period

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;

View solution in original post


All Replies
Solution
‎07-19-2013 12:34 PM
Trusted Advisor
Posts: 1,908

Re: Determine if the first occurence of a record was during a given period

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;

Regular Contributor
Posts: 186

Re: Determine if the first occurence of a record was during a given period

Posted in reply to PaigeMiller

Works like a charm and makes much sense.

Thank you very much for your help!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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