BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasseln
Obsidian | Level 7

Hi Team,

 

I have read a lot of posts on that Error, but unfortunately none of these could solve my Error.

So I have a dataset with the variables d_2006, erw_2006 for each year till d_2015 and erw_2015 and only one observation.

I want to compute the SMR for all of these years within a macro.

The variables smr, smr_u, and smr_o don't exist but should be created by the array.

 

data out_&number;							
	set out;
		amph = "&nenner"; 					

		array smr [10] smr2006 smr2007 smr2008 smr2009 smr2010 smr2011 smr2012 smr2013 smr2014 smr2015;
		array smr_u [10] smr_u2006 smr_u2007 smr_u2008 smr_u2009 smr_u2010 smr_u2011 smr_u2012 smr_u2013 smr_u2014 smr_u2015;
		array smr_o [10] smr_o2006 smr_o2007 smr_o2008 smr_o2009 smr_o2010 smr_o2011 smr_o2012 smr_o2013 smr_o2014 smr_o2015;
		array erw_ erw_2006-erw_2015;
		array d_ d_2006-d_2015;
		do i = 2006 to 2015;

		if erw_{i} =0 then smr{i} = d_{i};
		if erw_{i} >0 then smr{i} = d_{i}/erw_{i};

		if d_{i} =0 then smr_u{i} =0; 
		if d_{i} >0 & erw_{i} >0 then smr_u{i} = (d_{i}*((1-(1/(9*d_{i}))-(1.959963985/(3*sqrt(d_{i})))))**3)/erw_{i}; 
		if d_{i} >0 & erw_{i} =0 then smr_u{i} = (d_{i}*((1-(1/(9*d_{i}))-(1.959963985/(3*sqrt(d_{i})))))**3);	

		if erw_{i} >0 then smr_o{i} = ((d_{i}+1)*((1-(1/(9*(d_{i}+1)))+(1.959963985/(3*(sqrt(d_{i}+1))))))**3)/erw_{i};
		if erw_{i} =0 then smr_o{i} = ((d_{i}+1)*((1-(1/(9*(d_{i}+1)))+(1.959963985/(3*(sqrt(d_{i}+1))))))**3);
		end;
		drop i; 
run;

I've tried a lot of changes but stil get the ERROR: Array subscript out of range at...

 

Does anybody know where the fault is?

 

That would be great! Thanks a lot for help.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Two solutions.

1)


		do i = 1 to 10;

 2)

array smr [2006:2015] smr2006 smr2007 smr2008 smr2009 smr2010 smr2011 smr2012 smr2013 smr2014 smr2015;
		array smr_u [2006:2015] smr_u2006 smr_u2007 smr_u2008 smr_u2009 smr_u2010 smr_u2011 smr_u2012 smr_u2013 smr_u2014 smr_u2015;
		array smr_o [2006:2015] smr_o2006 smr_o2007 smr_o2008 smr_o2009 smr_o2010 smr_o2011 smr_o2012 smr_o2013 smr_o2014 smr_o2015;
		array erw_[2006:2015] erw_2006-erw_2015;
		array d_[2006:2015] d_2006-d_2015;
		do i = 2006 to 2015;

View solution in original post

4 REPLIES 4
Ksharp
Super User

Two solutions.

1)


		do i = 1 to 10;

 2)

array smr [2006:2015] smr2006 smr2007 smr2008 smr2009 smr2010 smr2011 smr2012 smr2013 smr2014 smr2015;
		array smr_u [2006:2015] smr_u2006 smr_u2007 smr_u2008 smr_u2009 smr_u2010 smr_u2011 smr_u2012 smr_u2013 smr_u2014 smr_u2015;
		array smr_o [2006:2015] smr_o2006 smr_o2007 smr_o2008 smr_o2009 smr_o2010 smr_o2011 smr_o2012 smr_o2013 smr_o2014 smr_o2015;
		array erw_[2006:2015] erw_2006-erw_2015;
		array d_[2006:2015] d_2006-d_2015;
		do i = 2006 to 2015;
sasseln
Obsidian | Level 7

Great, thank you! That was easy! 🙂

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Classic Excel thinking!  You could save yourself some headaches and re-model your data:

YEAR   SMR    SMR_U    SMR_O  ERW  D

 

In this way your data goes down the page, and calculations and such like are simplified down to their base coding, for example:

if d_{i} >0 & erw_{i} >0 then smr_u{i} = (d_{i}*((1-(1/(9*d_{i}))-(1.959963985/(3*sqrt(d_{i})))))**3)/erw_{i}; 

To:

if d > 0 and erw > 0 then smr_u=(d*((1-(1/(9*d))-(1.959963985/(3*sqrt(d)))))**3)/erw; 

Another benefit to this setup is that it does not matter how many years there are, if the number expands to 50 or 100 years the code remains untouched, in your example however the code expands rapidly.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1317 views
  • 4 likes
  • 4 in conversation