I have 3 columns: station, collection_date (as mm/yyyy), and wq_msmt. Each station was visited monthly for six years and and a wq_msmt was made. I want to use an array to have a column for each mm/yyyy, thus 72 columns, with the value under that column being that month's wq_msmt at a particular station, so there is one more column for station giving a total of 73 columns.
In essence, I want to go from a long, narrow data structure to a short, wide data structure. But, I think having collection date as a variable is throwing off my program as I get the error: ERROR: Array subscript out of range at line 114 column 5
Do arrays handle dates?
My code is below.
array mon mon1-mon72;
if first.FK_STATION then do i=1 to 72;
if last.FK_STATION then output;
keep FK_STATION mon1-mon72;
Collection date as a variable is not your problem.
In your sample you refer to "c_date"! Consistent naming would help with the diagnosis.
I presume you know what SAS dates are, and therefore, if collection date is a real date which has a format of "mm/yyyy" associated with it, then your array will be in range for 1 Jan 1960 until the early part of March in the same year. After that, the date value is higher than 72 and the subscript will be out of range.
A solution is to count the number of months and add the month number as a cohort to the data set and use this for the array definition. Bear in mind that if you calculate the cohort using the IntNx() function and use the first month as your from date, then your first month will be 0 and not 1. 0 is also out of range, so you need to increment from one month prior to the first observation month.
Assuming you are analysing a six year period from Jan 2000 to Dec 2005, the following may help:
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.