Sas loop nested

Reply
New Contributor
Posts: 2

Sas loop nested

[ Edited ]

hello everybody,

i'm a novice in sas programming and need some help to make working a data step which purpose is to clean duplicates entries from an array of random numbers.

any help will be appreciated.

thanks

 

Variables are:

Pieces is initialized at 20
Array1-648 contains: 559,543,396,404,163,655,172,5,477,642,363,408,441,306,540,367,2,424,492,24,94,342,....

and the code is:

data _null_;
 do _j_ = 2 to &Pieces.;
  do _k_ = sum(_i_,-1) to 1 by -1;
   if &&Array&_j_.. = &&Array&_k_.. then do;
    do _l_ = sum(_j_,1) to sum(&Nobs.,-1);
     Array&_j_. = Array&_l_.;
    end;
   Nobs = sum(Nobs,-1);
   _k_ = _j_;
   end;
  end;
 end;
run;

 

SAS log returns:

SYMBOLGEN:  Macro variable SYSERR resolves to 0
MLOGIC(CAMPIONE_OUTSOURCER):  %IF condition &syserr. gt 6 is FALSE
MPRINT(CAMPIONE_OUTSOURCER):   data _null_;
SYMBOLGEN:  Macro variable PIECES resolves to 20
MPRINT(CAMPIONE_OUTSOURCER):   do _j_ = 2 to 20;
MPRINT(CAMPIONE_OUTSOURCER):   do _k_ = sum(_i_,-1) to 1 by -1;
SYMBOLGEN:  && resolves to &.
WARNING: Apparent symbolic reference _J_ not resolved.
SYMBOLGEN:  Unable to resolve the macro variable reference &_j_
NOTE: Line generated by the macro variable "_J_".
1      &Array&
       -
       22
WARNING: Apparent symbolic reference ARRAY not resolved.
WARNING: Apparent symbolic reference _J_ not resolved.
NOTE 137-205: Line generated by the invoked macro "CAMPIONE_OUTSOURCER".
12          data _null_;         do _j_ = 2 to &Pieces.;             do _k_ = sum(_i_,-1) to 1 by -1;
12  !                 if &&Array&_j_.. = &&Array&_k_.. then do;                     do _l_ =
                                 ----
                                 22
12  ! sum(_j_,1) to sum(&Nobs.,-1);                         Array&_j_. =
ERROR 22-322: Syntax error, expecting one of the following: un nome, una stringa tra apici,
              una costante numerica, una costante di data e ora, un valore mancante, INPUT, PUT.

ERROR 22-322: Syntax error, expecting one of the following: un nome, una stringa tra apici,
              una costante numerica, una costante di data e ora, un valore mancante, arrayname, (, +,
              -, INPUT, NOT, PUT, ^, _NEW_, ~.

SYMBOLGEN:  && resolves to &.
WARNING: Apparent symbolic reference _K_ not resolved.
SYMBOLGEN:  Unable to resolve the macro variable reference &_k_
NOTE: Line generated by the invoked macro "CAMPIONE_OUTSOURCER".
12          data _null_;         do _j_ = 2 to &Pieces.;             do _k_ = sum(_i_,-1) to 1 by -1;
12  !                 if &&Array&_j_.. = &&Array&_k_.. then do;                     do _l_ =
                                 ----
                                 201
12  ! sum(_j_,1) to sum(&Nobs.,-1);                         Array&_j_. =
ERROR 201-322: The option is not recognized and will be ignored.

 

Trusted Advisor
Posts: 1,114

Re: Sas loop nested

Hello @rinaldosoprani,

 

You're mixing data step and macro language. There are much better ways to store 648 random numbers than macro variables, e.g. a SAS dataset. So, you'll make your life much easier if you go back to the code where you populated Array1-Array648 and take a different approach. Just explain what you are trying to achieve. Then many forum members will be able to help you.

New Contributor
Posts: 2

Re: Sas loop nested

I tried using sql select distinct, but it puts data in growing order and so I lose random sequence
Ask a Question
Discussion stats
  • 2 replies
  • 250 views
  • 0 likes
  • 2 in conversation