SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

Dear all, 

 I get this error message on running this code. Please  can any one help?

data sankey_paths3;
        set sankey_paths2;
        by starting_node ending_node start end;
        
        /**Hold running totals for group counts**/
        array start_n {&n_nodes,&n_grps} (%sysevalf(&n_nodes*&n_grps)*0) ;
        array end_n {&n_nodes,&n_grps} (%sysevalf(&n_nodes*&n_grps)*0) ;
                
        /***Build the Bezier Curve Connectors: Use Cubic Bezier Equation: 
            B(t)=(1-t)^3*P0 + 3(1-t)^2*t*P1 + 3(1-t)*t^2*P2 + t^3*P3, 0 <= t <= 1***/
        length path_index $20.;
        path_index=catx('-',starting_node,start_index,end_index);
        /*Find y-axis values for start/end corners of Bezier curves*/
        start_y1=start_group_min+start_group_diff*(start_n(starting_node,start_index)/start_group_n);
        start_y2=start_y1+start_group_diff*(n_move/start_group_n);
        end_y1=end_group_min+end_group_diff*(end_n(ending_node,end_index)/end_group_n)+end_group_diff*(n_move/end_group_n);
        end_y2=end_y1-end_group_diff*(n_move/end_group_n);
        /**Bezier Curve 1: From Left group to Right Group path**/
        do t = 0 to 1 by 1/25;
            x=((1-t)**3)*start_group_x+
                3*((1-t)**2)*t*(start_group_x+(end_group_x-start_group_x)/3)+
                3*(1-t)*(t**2)*(start_group_x+2*(end_group_x-start_group_x)/3)+
                (t**3)*end_group_x;
            y=((1-t)**3)*start_y2+3*((1-t)**2)*t*start_y2+3*(1-t)*(t**2)*end_y1+(t**3)*end_y1;
            output;
        end;
        /**Bezier Curve 2: From Right Group back to Left Group**/
        do t = 0 to 1 by 1/25;
            x=((1-t)**3)*end_group_x+
                3*((1-t)**2)*t*(start_group_x+2*(end_group_x-start_group_x)/3)+
                3*(1-t)*(t**2)*(start_group_x+(end_group_x-start_group_x)/3)+
                (t**3)*start_group_x;
            y=((1-t)**3)*end_y2+3*((1-t)**2)*t*end_y2+3*(1-t)*(t**2)*start_y1+(t**3)*start_y1;
            output;
        end;
        /**Increase running total for each groups N**/
        start_n(starting_node,start_index)+n_move;
        end_n(ending_node,end_index)+n_move;
        
        keep x y path_index start n_move;
    run;

This is the message in log (I have attached a test dataset):

ERROR: Array subscript out of range at row 67 column 176.
starting_node=1 start=16 start_group_n=1
start_group_min=90.714285714 start_group_max=95.714285714
start_group_diff=5 start_group_x=5 start_index=7 ending_node=2
end=2 end_group_n=14 end_group_min=0 end_group_max=70
end_group_diff=70 end_group_x=33.333333333 end_index=1 n_move=1
FIRST.starting_node=0 LAST.starting_node=1 FIRST.ending_node=0
LAST.ending_node=1 FIRST.start=1 LAST.start=1 FIRST.end=1
LAST.end=1 start_n1=0 start_n2=0 start_n3=0 start_n4=0
start_n5=0 start_n6=0 start_n7=0 start_n8=0 start_n9=0
start_n10=0 start_n11=0 start_n12=0 start_n13=0 start_n14=0
start_n15=0 start_n16=0 start_n17=0 start_n18=0 start_n19=0
start_n20=0 start_n21=0 start_n22=0 start_n23=0 start_n24=0
end_n1=0 end_n2=0 end_n3=0 end_n4=0 end_n5=0 end_n6=0 end_n7=0
end_n8=0 end_n9=0 end_n10=0 end_n11=0 end_n12=0 end_n13=0
end_n14=0 end_n15=0 end_n16=0 end_n17=0 end_n18=0 end_n19=0
end_n20=0 end_n21=0 end_n22=0 end_n23=0 end_n24=0
path_index=1-7-1 start_y1=. _ERROR_=1 _N_=7
NOTE: The SAS System stopped processing this step because of
      errors.
NOTE: There were 8 observations read from the data set
      WORK.SANKEY_PATHS2.
WARNING: The data set WORK.SANKEY_PATHS3 may be incomplete.
         When this step was stopped there were 6 observations
         and 67 variables.


 

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

The error message gives you a nice clue. At least one of your arrays fail to include the values of starting_node, start_index, ending_node and end_index.

 

When you create the &n_nodes and &n_groups macro variables, make sure that they are 'large enough' to hold the values of the four variables above.

Anita_n
Pyrite | Level 9

I don't understand why this is not  large enough. Please can you explain?

 

Anita_n_0-1684920596101.png

These are the number of groups I have in each node. Its being working for other datasets, I don't know why it's not working here

PeterClemmensen
Tourmaline | Level 20

I don't know what this data is?

 

However, to help you the best: Take a look at the 7th observation of your input data. This is where the error happens when the data step reads the data (_N_ = 7).

 

One of the four variable values here do not fit within the index values of the arrays.

Anita_n
Pyrite | Level 9

unfortunately I cannot fishout the problem

yabwon
Onyx | Level 15

My first thought is that one of those 4GL variables:

starting_node,start_index,ending_node,end_index

has value outside of array dimensions.

Their values are:

starting_node=1
start_index=7
ending_node=2
end_index=1

 one of them must be greater than:

&n_nodes
&n_grps
&n_nodes
&n_grps

 

Add `%put` before data step to see what values those 4 macrovariables have.

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Anita_n
Pyrite | Level 9

@PeterClemmensen @yabwon thankyou, I don't know why or what happend but I created the input data again and run

the code again and it's now working

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1359 views
  • 3 likes
  • 3 in conversation