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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 989 views
  • 0 likes
  • 2 in conversation