Look down below Scott! I did it! Thanks for the push. Here's how I did it.
%macro create(howmany);
data total;
set &status._tot;
by varnum;
if first.varnum then valnum=0;
valnum+1;
run;
data tempcnt(keep=varnum valnum);
set total;
by varnum valnum;
if last.varnum eq 1 then output;
run;
data total;
merge total tempcnt(rename=(valnum=maxcnt));
by varnum;
run;
%do i=1 %to &howmany;
data &status._y_&i;
set total;
by varnum valnum;intval=&howmany;
if _n_=1 then betaY&i=&i;
if last.varnum ne 1 or sum(last.varnum,first.varnum) eq 2
then do;
betaY&i=betaY&i + intval;
retain betaY&i;
output;
end;
%end;
PUTLOG '>DIAG00' /_ALL_;
run;
*proc print data=trans1_y_1;run;
***re-read original TOTAL data set to pull the nth observation for each variable;
***set betaval as the cumulative betaval of values preceding it(for like variables);
data &status.nthval;
set total;
by varnum valnum;
if last.varnum eq 1 and sum(last.varnum,first.varnum) ne 2;
PUTLOG '>DIAG00' /_ALL_;
run;
proc print data=&status.nthval;
run;
data downsize(keep = varnum betay1);
set trans1_y_1;*&status._y_&i; ***this is causing the problem i is not defined outside the loop***
run;
proc transpose data=downsize out=betaside;
by varnum;
run;
options missing='';
data concat;
set betaside(drop=_name_);
sp=',';
array col{*} col:;
do i=1 to dim(col);
betay1=catx(sp,of col:);
end;
run;
data &status.nthval;
merge &status.nthval(in=a) concat(in=b keep=varnum betay1);
by varnum;
if a and b;
run;
proc print data=&status.nthval;
run;
%mend create;
varnum valnum maxcnt betay1
1 3 3 3,5
2 2 2 7
3 9 9 9,11,13,15,17,19,21,23
4 3 3 25,27
6 2 2 31
7 2 2 33
8 3 3 35,37
9 5 5 39,41,43,45
10 3 3 47,49
11 6 6 51,53,55,57,59
12 7 7 61,63,65,67,69,71
13 4 4 73,75,77
I still have to merge it back in with the rest of the observation but I've cleared the hurdle.
I'll have more questions tomorrow. new day.