I have to select values from a table based on months. I have to select last 3 months data. Have already tried the following -
data _null_;
set a(obs=1);
prev_2_mon_dt = intnx('month',date(),-2,'beginning');
prev_2_mon = year(prev_2_mon_dt)*100 + month(prev_2_mon_dt);
call symput('pr2mn',prev_2_mon);
run;
data c;
set d;
if ordermth in (%eval(&pr2mn.),%eval(&pr2mn. + 1),%eval(&pr2mn. + 2));
run;
So it gives numebrs like - 201411,201412, 201413 etc..
Is there any other way to handle this issue ?
Your formula would produce something like 20152 rather than 201502.
I'd use something like:
data _null_;
prev_2_mon_dt = intnx('month',date(),-2,'beginning');
call symput('pr2mn',put(prev_2_mon_dt,yymmn6.));
call symput('curmn',put(date(),yymmn6.));
run;
data d;
input ordermth;
cards;
201410
201411
201412
201501
201502
201503
201504
201505
201506
;
data c;
set d;
if &pr2mn. le ordermth le &curmn.;
run;
What do your ordermth values look like?
They look like - 201410,201411, 201412,201501 etc..
They are calculated each time with the formula I used above. Year*100 + month.
It is calcualated from a timestamp but I don't have that timestamp information in the input file anymore..
Your formula would produce something like 20152 rather than 201502.
I'd use something like:
data _null_;
prev_2_mon_dt = intnx('month',date(),-2,'beginning');
call symput('pr2mn',put(prev_2_mon_dt,yymmn6.));
call symput('curmn',put(date(),yymmn6.));
run;
data d;
input ordermth;
cards;
201410
201411
201412
201501
201502
201503
201504
201505
201506
;
data c;
set d;
if &pr2mn. le ordermth le &curmn.;
run;
Thanks!!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.