Question

I have a DATE variable in my dataset in monthly format (Example: Ob1=5/1/2013, ob2=6/1/2013 etc).

I want to shift the dates back by one period. That is, for the entire row of data (18 variables), what was 6/1/2013, will now be 5/1/2013, under the same variable DATE.

So,

Previous data

Date  Var1  Var2 Var3

1/1/2013  A   10   30

2/10/2013  B   15   32

3/15/2013  C   12   36

4/30/2013  D   16   25

New data

Date  Var1  Var2 Var3

12/1/2012  A   10   30

1/10/2013  B   15   32

2/15/2013  C   12   36

3/30/2013  D   16   25
Was it helpful?

Solution

What you need is the INTNX function. More information here: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700.htm

e.g.:

data NEWDATA;
    set PREVIOUSDATA;
    Date = intnx('month',Date,-1,'same');
run;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top