BookmarkSubscribeRSS Feed
Louis_hen
Calcite | Level 5

Hi!

I am trying to complete my code for assigning a status on individuals on their labourmarket status. 

My code is the following:

 

data SPECIALE.merge_bf_self (compress=binary);

set SPECIALE.merge_dpsgdp;

 

array ydelser (*) $3 y_1901--y_2130;

array spell (135) $2;

array branche (*) $6 branche_2019_01--branche_2021_07;

 

do i='31dec2018'd to '30jul2021'd;

mdr=month(i);

aar=year(i);

dag=day(i);

ugedag=weekday(i);

 

dream=ceil(((i-'31dec2018'd)+1)/7);

index=0;

index=(aar-2019)*12 + mdr;

 

if branche(index) not in ('','') then do;

if ydelser(dream)=('') then spell(dream)="B";

 

end;

if ydelser(dream)=('') and spell(dream)=('') then spell(dream)="SF";

end;

run;

 

However when I run the code, then there pops an error with the message that array subscript out of range at line 46 column 4

 

My data is contructed in the following way, where the data contains different codes depending on the individuals status

IDy_1901...y_2130branche_2019_01...branche_2021_07spells
1       
2       
3       
4       
5       
6       
...       

 

Hope somebody can help, since I can't locate the error

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please show us the entire LOG, all of it, every single line, every single character, so we can know what line 46 contains. Do not show us just line 46.

 

Please format the log properly so we can read it easily. You do this by copying the log as text and pasting it into the window that appears when you click on the </> icon here in the SAS Communities. DO NOT SKIP THIS STEP.

 

In the future, whenever there is an error in the log, please follow all of the above instructions.

--
Paige Miller
Tom
Super User Tom
Super User

The log will tell you more information that will help you figure this out.  In particular it should show you which line of code is line # 46 in this session.  It will also show you the values for all of the variables at the time the error was detected.  So check the value of the variables that you used as array indexes.  Also check the value of the _N_ automatic variable to see which observation caused the issue.

 

Sounds like your data is poorly structured for what you want to do.  Your could would probably be a lot simpler if each date was its own observation instead of trying to make so many variables.  To get more help describe what you are trying to do.  What is the source data?  What is the desired output?  Is it a report? A dataset? What will the dataset be used for?  

ballardw
Super User

How many variables are in Arrays ydelser  . COUNT them. If you do not have at least 135 variable  then the expression :

ydelser(dream)

is the culprit when Dream exceeds the number of  variables in the array.

If you don't know the number you can easily check with the DIM function: numelements=dim(arrayname)

Or if Branche actually has fewer than 31 variables

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 3 replies
  • 839 views
  • 0 likes
  • 4 in conversation