BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aminkarimid
Lapis Lazuli | Level 10

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!

 

 

 

1 ACCEPTED SOLUTION
4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

 

 

 

 

Kurt_Bremser
Super User

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.

aminkarimid
Lapis Lazuli | Level 10
The CONTENTS Procedure:
Alphabetic List of Variables and Attributes # Variable Type Len Format Informat Label 5 6 1 4 2 3 7 8
CountedVOLUMENum8   
IntradayVolumeNum8   
TRD_EVENT_DTChar10$10.$10.TRD_EVENT_DT
TRD_EVENT_ROUFORChar5   
TRD_EVENT_TMChar8$8.$8.TRD_EVENT_TM
TRD_STCK_CDChar5$5.$5.TRD_STCK_CD
VolumeNum8  Volume
adjusted_volumeNum8   

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 540 views
  • 2 likes
  • 3 in conversation