You should probably use metadata to generate the code.
proc contents data=have noprint out=contents; run;
proc sql noprint;
create table pairs as
select a.name as LP
, b.name as HP
from contents a
inner join contents b
on upcase(substr(a.name,length(a.name)-2))
= upcase(substr(b.name,length(b.name)-2))
and upcase(a.name) like '%^_LP' escape '^'
and upcase(b.name) like '%^_HP' escape '^'
order by a.varnum
;
select lp,hp into :lp separated by ' ', :hp separated by ' '
from pairs
;
quit;
data want ;
set have;
array lp &lp;
array hp &hp;
do i=1 to dim(lp);
lp(i)=coalesce(lp(i),hp(i));
end;
run;
... View more