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

I'm assuming that this is a problem using IN in PROC FCMP. The following is the log.

184  proc fcmp OUTLIB=GACLUSTR.FUNCTIONS.GACLUSTER;

185

186   function runConnectivity2(cl

  • ,near[*,*],num_near);
  • WARNING: Function runConnectivity2 is already defined in packet GACLUSTER. Function

             runConnectivity2 as defined in the current program will be used as default when packet

             is not specified.

    187     label='Runs Connectivity to find the connectedness measure for cluster cl.';

    188     * cl is the indexes of the cluster in ascending order, near is the matrix of

    189       the nearest neighbors, one row for each unit in the population, num_near

    190       is the number of nearest neighbors that contribute to measure. The units in a

    191       row are in ascending order of nearness. num_near must be less than or equal

    192       to the second dimension of near. Returns -1 if num_near is greater than

    193       the second dimension of near.;

    194

    195

    196  if num_near > dim2(near) then return(-1);

    197  s=0;

    198  do i = 1 to dim(cl);

    199    ii=cl;

    200    put near=;

    201     do j=1 to num_near;

    202       if ~(near[ii, j] in cl) then s=s+1/j;

                                 --

                                 22

                                 76

    ERROR 22-322: Syntax error, expecting one of the following: (, :.

    ERROR 76-322: Syntax error, statement will be ignored.

    203     end;

    204  end;

    205  return(s);

    206  endsub;

    207

    208  run;

    NOTE: Execution aborted because of errors in program.

          Reenter the corrected program or enter "QUIT;" to exit procedure.

    209

    210

    211  quit;

    NOTE: The SAS System stopped processing this step because of errors.

    NOTE: PROCEDURE FCMP used (Total process time):

          real time           0.84 seconds

          cpu time            0.12 seconds

    212

    213  options cmplib=GACLUSTR.FUNCTIONS;

    214  data _null_;

    215  array c{6} _TEMPORARY_ (1 3 4 7 9 11);

    216  k=6;

    217  /*array c{3} _TEMPORARY_ (9 10 11);

    218  k=3;*/

    219  array a{17,10} _TEMPORARY_

    220  (2  3   4   7   5   6   8   9   10  11

    221  4   3   5   1   6   7   8   9   10  11

    222  2   1   7   4   6   5   8   9   10  11

    223  5   2   6   7   3   1   8   9   10  11

    224  4   6   2   7   8   3   1   9   10  11

    225  5   7   4   2   8   3   1   9   10  11

    226  6   3   4   2   5   8   1   9   10  11

    227  12  9   13  14  6   7   5   15  4   2

    228  13  14  8   15  7   6   5   16  3   10

    229  11  16  17  9   15  14  13  12  8   7

    230  10  17  16  13  14  9   12  15  8   7

    231  13  14  9   8   15  6   16  5   7   4

    232  14  12  9   15  8   16  7   6   5   10

    233  13  12  9   15  8   16  7   6   5   10

    234  14  13  12  9   8   16  10  7   6   5

    235  17  10  15  11  14  13  9   12  6   7

    236  16  10  11  15  14  13  12  9   8   6);

    237

    238

    239  nm=5;

    240  s=0;

    241  do i = 1 to dim(c);

    242    ii=c;

    243    *put 'before ' i= ii= s=;

    244     do j=1 to nm;

    245       if ~(a[ii,j] IN c) then s=s+1/j;

    246     end;

    247     *put 'after ' i= ii= s=;

    248  end;

    249  put s=;

    250

    251  *sum=runConnectivity2(c,a,nm);

    252  *put sum=;

    253  *if sum=-1 then put 'num_near ' nm 'is greater than second dimension of a ' d2_a;

    254

    255  run;

    s=10.05

    NOTE: DATA statement used (Total process time):

          real time           0.01 seconds

          cpu time            0.01 seconds

    The log shows a snippet of the code that works in a data step but I get a syntax error when it is being defined as a function in FCMP. I've tried all manner combinations such as putting ( ) around cl, using cl

  • , using 'of cl', putting the array into the function definition and appropriately changing the names so that the variable references are correct and not conflicted.
  • 1 ACCEPTED SOLUTION

    Accepted Solutions
    dmluery
    Calcite | Level 5

    FriedEgg,

    Thank you for your answer, it works very well for me. I  keep on being asked for a status update. I haven't determined how to do this yet.

    View solution in original post

    3 REPLIES 3
    FriedEgg
    SAS Employee

    Can't use array in the way with FCMP

    if you want to see a more meaningful (barely) error message use the following in FCMP:

    proc fcmp;

    array a[5] ( 1 2 3 4 5 );

    if 4 in ( a ) then put 'its there';

    run;

    ERROR: The array a cannot be an argument of the 'IN' operation at line.

    The WHICHN and CHOOSEN functions also do not like array references in FCMP

    proc fcmp;

    function in_arrayn( v , a

  • );
  • x=0;

    do i = 1 to dim(a);

        x+(v=a);

      end;

    return (x);

    endsub;

    function b( cl

  • , near[*,*] , num_near );
  • s=0;

    do i = 1 to dim( cl );

      ii = cl;

      do j = 1 to num_near;

          if in_arrayn( near[ii,j] , cl ) = 0 then s+1/j;

      end;

    end;

    return (s);

    endsub;

    array c[6] (1 3 4 7 9 11);

    array a[17,10]

    (2  3   4   7   5   6   8   9   10  11

      4   3   5   1   6   7   8   9   10  11

      2   1   7   4   6   5   8   9   10  11

      5   2   6   7   3   1   8   9   10  11

      4   6   2   7   8   3   1   9   10  11

      5   7   4   2   8   3   1   9   10  11

      6   3   4   2   5   8   1   9   10  11

      12  9   13  14  6   7   5   15  4   2

      13  14  8   15  7   6   5   16  3   10

      11  16  17  9   15  14  13  12  8   7

      10  17  16  13  14  9   12  15  8   7

      13  14  9   8   15  6   16  5   7   4

      14  12  9   15  8   16  7   6   5   10

      13  12  9   15  8   16  7   6   5   10

      14  13  12  9   8   16  10  7   6   5

      17  10  15  11  14  13  9   12  6   7

      16  10  11  15  14  13  12  9   8   6);

    sum=b(c,a,5);

    put sum=;

    run;

    dmluery
    Calcite | Level 5

    FriedEgg,

    Thank you for your answer, it works very well for me. I  keep on being asked for a status update. I haven't determined how to do this yet.

    FriedEgg
    SAS Employee

    In the top navigation bar click the create button, then click Status Update, voila.  Glad you found the previous post helpful.

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

    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.

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