> how do I save it into its own dataset
You can use the CREATE and APPEND statements in PROC IML to write data to a SAS data set. See
Writing data from a matrix to a SAS data set - The DO Loop
If you specify what is wrong with the code (and also supply example data), we can assist on your other issues.
... View more