Help using Base SAS procedures

Code help

Reply
N/A
Posts: 0

Code help

Hi,

I have a column with month data.

Month
200901
200811
200810
;;;;

I need to find the maximum of the month column, and date back to 24 months from max month value.

In the above example the max month is 200901. I need to take that value and create an array of 23 past months.

How to do this in SAS?

Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: Code help

Posted in reply to deleted_user
Using a DATA step, first, convert these character strings to SAS DATE variables using the INPUT function in an assignment statement, then after identifying your maximum value, setup a DO / END loop to iteratate from 1 to 24, as shown below:

%LET RANGE = 24;
DATA _NULL_;
RETAIN MYDATE "&SYSDATE9"D;
FORMAT MYDATE DATE9.;
ARRAY APDVALS (*) PDVAL1-PDVAL⦥
FORMAT PDVAL: YYMMN6.;
* now load up the array based on the date var MYDATE. ;
DO X = 1 TO ⦥
APDVALS(X) = INTNX('MONTH',MYDATE,-X);
END;
* now show the results to the SASLOG - formatted for effect. ;
PUTLOG _ALL_;
RUN;


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 1 reply
  • 100 views
  • 0 likes
  • 2 in conversation