BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1030 views
  • 0 likes
  • 2 in conversation