Hi all.
I have a dataset with two variables, MY_ID and MY_DATE. The record MY_DATEs are all between the two year period of '01JUN2016'D AND '31MAY2018'D.
Using Proc SQL, I need to pull the IDs that are present with MY_DATEs between '01JUN2017'D AND '31MAY2018'D, but NOT also present between '01JUN2016'D AND '31MAY2017'D.
Does anyone have a suggest for a good way to code this? Any help would be greatly appreciated.
@buechler66 wrote:
Hi all.
I have a dataset with two variables, MY_ID and MY_DATE. The record MY_DATEs are all between the two year period of '01JUN2016'D AND '31MAY2018'D.
Using Proc SQL, I need to pull the IDs that are present with MY_DATEs between '01JUN2017'D AND '31MAY2018'D, but NOT also present between '01JUN2016'D AND '31MAY2017'D.
Does anyone have a suggest for a good way to code this? Any help would be greatly appreciated.
Should be straight forward to translate your problem statement into SQL
/* Using Proc SQL, I need to pull
the IDs that are present with MY_DATEs between '01JUN2017'D AND '31MAY2018'D
, but NOT also present between '01JUN2016'D AND '31MAY2017'D.
*/
proc sql ;
select distinct MY_ID from have
where MY_DATE between '01JUN2017'D AND '31MAY2018'D
except
select distinct MY_ID from have
where MY_DATE between '01JUN2016'D AND '31MAY2017'D
;
quit;
@buechler66 wrote:
Hi all.
I have a dataset with two variables, MY_ID and MY_DATE. The record MY_DATEs are all between the two year period of '01JUN2016'D AND '31MAY2018'D.
Using Proc SQL, I need to pull the IDs that are present with MY_DATEs between '01JUN2017'D AND '31MAY2018'D, but NOT also present between '01JUN2016'D AND '31MAY2017'D.
Does anyone have a suggest for a good way to code this? Any help would be greatly appreciated.
Should be straight forward to translate your problem statement into SQL
/* Using Proc SQL, I need to pull
the IDs that are present with MY_DATEs between '01JUN2017'D AND '31MAY2018'D
, but NOT also present between '01JUN2016'D AND '31MAY2017'D.
*/
proc sql ;
select distinct MY_ID from have
where MY_DATE between '01JUN2017'D AND '31MAY2018'D
except
select distinct MY_ID from have
where MY_DATE between '01JUN2016'D AND '31MAY2017'D
;
quit;
I would propose:
proc sql ;
select * from have as a
where
MY_DATE between '01JUN2017'D AND '31MAY2018'D and
not exists ( select * from have
where My_ID = a.MY_ID and
MY_DATE between '01JUN2016'D AND '31MAY2017'D )
;
quit;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.