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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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