For your dsn array, just put a number immediately after the $ to declare a length. array dsn{12} $50 dsn01a dsn02a. etc. To make this fully dynamic, I think you would need to know how many righ* or left* variables you have prior to the data step. Pop that into a macro variable and use that to declare your arrays. It's the new variable array that is the problem. Unfortunately, I don't think you can use a variable value for the subscript. If you knew the number of variables, you could declare the arrays like:
%let varnum=25; /* Get this by querying dictionary tables */
data x;
set tst;
array lt{&varnum} $ righ:;
array rt{&varnum} $ left:;
array dsn{&varnum} $9;
......
This will name your new variables dsn1 dsn2 dsn3, etc. If you need them exactly as you have in the example above (dsn01a, dsn02a, etc), then you will need a macro-based approach like @smantha has below.
... View more