Help using Base SAS procedures

set a date range from a data set

Reply
New Contributor HTG
New Contributor
Posts: 2

set a date range from a data set

 Hi, I am writing the below mentioned codes to churn out results from a data set with a specific date range. I set the date as 15dec2015 to get results for 01dec2015 to 31dec2015. The majority of the churned result are from dec2015 but consists some of the earlier result from 2012 to Nov 2015. Can you advise on how I can get the churned results only from dec2015? Below is the code:

 

libname mis_data "E:\GCC Data Mart\Monthly MIS\Unsecured\FE_Deck\Data"

 

%let setdt='15DEC2015'd;

 

data _null_;

curr=intnx('month',&setdt,0);

curr=intnx('day',curr,-1);

   

call symput("yymm",put(curr,yymmn4.));

call symput("yyyymmdd",put(curr,yymmddn8.));

call symput("dt",compress("'"||put(curr,date9.)||"'"||"d"));

run;

 

%put &yymm &yyyymmdd &dt;

Super User
Posts: 19,822

Re: set a date range from a data set

You need to show your filter as well. How you use the macro variables matters. 

Respected Advisor
Posts: 4,927

Re: set a date range from a data set

Assuming your data includes a SAS date variable (say myDate), all you need is to add the statement

 

where myDate between intnx("MONTH", &setdt, 0, "BEGINNING") and intnx("MONTH", &setdt, 0,"END");

 

to your data step, or the clause

 

where myDate between intnx("MONTH", &setdt, 0, "BEGINNING") and intnx("MONTH", &setdt, 0,"END")

 

to your SQL query.

 

If your date variable is a SAS datetime, replace "MONTH" by "DTMONTH".

PG
New Contributor HTG
New Contributor
Posts: 2

Re: set a date range from a data set

Thanks PG.

Ask a Question
Discussion stats
  • 3 replies
  • 318 views
  • 0 likes
  • 3 in conversation