DATA Step, Macro, Functions and more

Finding previous months data?

Reply
Contributor
Posts: 73

Finding previous months data?

Trying to accomplish following:

DATA TABLE1;
 SET TABLE2
     TABLE3
     TABLE4
     TABLE5;
KEEP OBS1 OBS2 OBS3;
WHERE INTNX('MONTH', OBS4, 0) = INTNX('MONTH', TODAY(), -1);

OBS4 is DATETIME21.2 formatted.

 

I've tried:

PMONTH=INTNX('MONTH', OBS4, 0);

and it comes back null.

Super User
Super User
Posts: 7,413

Re: Finding previous months data?

If it is a datetime variable that means you would need to put datepart() around the variable.  E.g;

where intnx('MONTH', datepart(OBS4), 0) = intnx('MONTH', today(), -1);

 

Valued Guide
Posts: 858

Re: Finding previous months data?

[ Edited ]

Here is a solution:

 

data have;
input obs4;
informat obs4 datetime21.2;
format obs4 datetime21.2;
cards;
27OCT2015:05:39:48.00
;

data want;
set have;
format pmonth date9.;
pmonth = intnx('month',datepart(obs4),-1,'same');
run;

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