Rhea
Rhea

Reputation: 293

Assign an array's value as a dimension to another array in SAS

I've been working on a complicated code and am stuck in the end, where I need to assign one array's value as a dimension parameter to another array in the code. A snapshot from my code : For example:

array temp_match_fl(3) temp_match_fl1 - temp_match_fl3;     
    ARRAY buracc_repay(3) buracc_repay1 - buracc_repay3;
    ARRAY ocs_repay(3) ocs_repay1 - ocs_repay3;
    jj = 0;
    do until (jj>=3);
    jj=jj+1;

    If length(strip(match_flag(jj))) = 1 then do;
        temp_match_fl(jj) = match_flag(jj);
    end;

    Else If length(strip(match_flag(jj))) > 1 then do; 
        j1 = 0; 
        min_diff = 99999999;    
        do until (j1>=length(strip(match_class(jj))));
           j1=j1+1;
           retain min_diff;
            n=substr(strip(match_flag(jj)),j1,1);
            If (min_diff > abs(buracc_repay(jj)-ocs_repay(n))) then do;
                min_diff = abs(buracc_repay(jj)-ocs_repay(n));
                temp_match_fl(jj) = n;              
            end;
        end;
    end;
    kk=temp_match_fl(jj);
/*  buracc_repay(jj) = ocs_repay(kk);*/
    buracc_repay(jj) = ocs_repay(temp_match_fl(jj));    
 end;
run;

Now, I need to be able to assign the value stored in temp_match_fl(jj) array as dimension parameter to another array, how can I achieve that?? None of the last two statements work:

buracc_repay(jj) = ocs_repay(kk); buracc_repay(jj) = ocs_repay(temp_match_fl(jj)); Can someone please suggest. Thanks!

Upvotes: 0

Views: 170

Answers (1)

Quentin
Quentin

Reputation: 6378

Actually your last two statements as written do work. Are you getting an error, or unexpected results? Can you make a simple example like below that shows the problem?

Note that for this to work, it's essential that the value of temp_match_fl(jj) is 1, 2, or 3, because your OCS_REPAY array has three elements. From the code you've shown, it's not clear if that is always true. You don't show the match_flag array.

data want ;
  array temp_match_fl(3) temp_match_fl1 - temp_match_fl3 (1 2 3) ;     
  array buracc_repay(3) buracc_repay1 - buracc_repay3 (10 20 30) ;
  array ocs_repay(3) ocs_repay1 - ocs_repay3  (100 200 300) ;

  jj=1 ;
  kk=2 ;

  *buracc_repay(jj) = ocs_repay(kk);  *this works ;

  put temp_match_fl(jj)= ; *debug to confirm value is 1 2 or 3 ;

  buracc_repay(jj) = ocs_repay(temp_match_fl(jj)); *this also works;

  put (buracc_repay:)(=) temp_match_fl1=; *check output ;
run ;

Upvotes: 1

Related Questions