Hello everybody;
Here is my code:
DATA Sampledata87_02_Mer_DumVar;
set Sampledata87_02_Mer;
ARRAY dummys {*} 8. TRD_EVENT_ROUFOR_1 - TRD_EVENT_ROUFOR_9;
DO i=1 TO 9;
dummys(i) = 0;
END;
dummys( TRD_EVENT_ROUFOR ) = 1;
RUN;
PROC FREQ DATA=Sampledata87_02_Mer_DumVar;
TABLES TRD_EVENT_ROUFOR*TRD_EVENT_ROUFOR_1*TRD_EVENT_ROUFOR_2*TRD_EVENT_ROUFOR_3*TRD_EVENT_ROUFOR_4*TRD_EVENT_ROUFOR_5*TRD_EVENT_ROUFOR_6*TRD_EVENT_ROUFOR_7*TRD_EVENT_ROUFOR_8*TRD_EVENT_ROUFOR_9 / list ;
RUN;
The log is:
220 DATA Sampledata87_02_Mer_DumVar;
221 set Sampledata87_02_Mer;
222
223 ARRAY dummys {*} 8. TRD_EVENT_ROUFOR_1 - TRD_EVENT_ROUFOR_9;
224
225 DO i=1 TO 9;
226 dummys(i) = 0;
227 END;
228 dummys( TRD_EVENT_ROUFOR ) = 1;
229
230 RUN;
ERROR: Array subscript out of range at line 228 column 3.
TRD_EVENT_DT=. TRD_EVENT_TM= TRD_STCK_CD= TRD_EVENT_ROUFOR= CountedVOLUME=. IntradayVolume=.
Volume=8.2246061E13 adjusted_volume=. TRD_EVENT_ROUFOR_1=0 TRD_EVENT_ROUFOR_2=0
TRD_EVENT_ROUFOR_3=0 TRD_EVENT_ROUFOR_4=0 TRD_EVENT_ROUFOR_5=0 TRD_EVENT_ROUFOR_6=0
TRD_EVENT_ROUFOR_7=0 TRD_EVENT_ROUFOR_8=0 TRD_EVENT_ROUFOR_9=0 i=10 _ERROR_=1 _N_=1
WARNING: The data set WORK.SAMPLEDATA87_02_MER_DUMVAR may be incomplete. When this step was
stopped there were 0 observations and 18 variables.
WARNING: Data set WORK.SAMPLEDATA87_02_MER_DUMVAR was not replaced because this step was stopped.
What is the problem? Which part of my code is wrong?
Thanks!
We already know what's happening. Make TRD_EVENT_ROUFOR numeric, and make sure that the values are in the range suitable for your array.
Look at your error mesaage:
ERROR: Array subscript out of range at line 228 column 3.
TRD_EVENT_DT=. TRD_EVENT_TM= TRD_STCK_CD= TRD_EVENT_ROUFOR= CountedVOLUME=. IntradayVolume=.
This is clearly showing both that A) trd_event_roufor is missing - which is invalid for an array index, and B) it is a character variable - you want a numeric variable.
In future, it is a good idea to post test data in the form of a datastep so we don't have to investigate these things (also code in lower case, it makes it far easier to read).
That:
NOTE: Character values have been converted to numeric values at the places given by:
is the pointer to the sloppy programming.
See my Maxim 25 (Clean log). Such NOTEs must not be tolerated, as they indicate that the programmer did not really take care of the type of one of the variables. Also see Maxim 3 (Know your data).
So you need to take a good look at the contents of this variable throughout the dataset (following Maxim 3), and convert it to numeric in the first place. A missing value cannot be tolerated if you want to use it for indexing into an array.
This will then mean that you follow Maxim 25.
CountedVOLUME | Num | 8 | |||
IntradayVolume | Num | 8 | |||
TRD_EVENT_DT | Char | 10 | $10. | $10. | TRD_EVENT_DT |
TRD_EVENT_ROUFOR | Char | 5 | |||
TRD_EVENT_TM | Char | 8 | $8. | $8. | TRD_EVENT_TM |
TRD_STCK_CD | Char | 5 | $5. | $5. | TRD_STCK_CD |
Volume | Num | 8 | Volume | ||
adjusted_volume | Num | 8 |
We already know what's happening. Make TRD_EVENT_ROUFOR numeric, and make sure that the values are in the range suitable for your array.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.