0
proc iml;
use rdata3;
read all var _all_ into pp;
close rdata3;
do i = 1 to 1050;
    perms = allperm(pp[i, ]);
    create pp&i from perms[colname= {"Best" "NA1" "NA2" "Worst"}];
    append from perms;
    close pp&i;
end;

I will like to create multiple datasets in SAS using the above code through a do loop. However, i cant seem to change the name of each dataset using the &i indicator. Can anyone help me change my code to allow me to create multiple datasets? Or are there any other alternatives on how to create multiple datasets from matrix through loops? Thanks in advance.

Sopon
  • 1
  • 2

1 Answers1

2

You don't want to use macro variables you want to use the features of IML. However you will be creating an awful lot of data sets.

data rdata3;
   x = 1;
   y = 2;
   a = 4;
   b = 5;
   output;
   output;
   run;
proc iml;
   use rdata3;
   read all var _all_ into pp;
   close rdata3;
   do i = 1 to nrow(pp);
      outname = cats('pp',putn(i,'z5.'));
      perms = allperm(pp[i, ]);
      create (outname) from perms[colname= {"Best" "NA1" "NA2" "Worst"}];
      append from perms;
      close (outname);
      end;
   quit;

You can add an ID variable to PERMS and append all versions of PERMS into one data set. I'm not sure I used the best IML technique, I know just enough IML to be dangerous.

proc iml;
   use rdata3;
   read all var _all_ into pp;
   close rdata3;
   perms = j(1,5,0);
   create PP_out from perms[colname= {'ID' "Best" "NA1" "NA2" "Worst"}];
   do i = 1 to nrow(pp);
      perms = allperm(pp[i, ]);
      perms = j(nrow(perms),1,i)||perms;
      append from perms;
      end;
   close PP_out;
   quit;
data _null_
  • 8,534
  • 12
  • 14
  • 1
    I agree with data_null_. You might want to add an ID variable to each set of permutations and then write a single data set that contains all data. You can then analyze the data with BY-group processing. – Rick Dec 23 '16 at 23:33
  • What should i use to join several datasets together into a single dataset? I think this is a better idea – Sopon Dec 25 '16 at 05:41
  • Thanks so much! Will u be able to help me with the other question i posted? – Sopon Dec 28 '16 at 07:54