I don't follow this logic. Eg how are the seqno determined? Why is Seqno=1 in the first two obs?
Please be more specific about how you get from your data now to your desired results
If I understand you correctly though
data have;
input (Viewnm tablenam thrcolname updtcoln flg1 upflg2 crflg3 qrflg4)($);
datalines;
Nm tabl1 accno acrnbr y n n n
Nm2 tbr2 accno crmnbr n n y n
Mn3 tbr2 accno crmnrcln n y n n
Nm4 tbr2 enitynr entynbr n n n y
;
data want;
format seqno refflg updtcoln;
set have;
array _{4} flg1--qrflg4;
do seqno=1 to dim(_);
put seqno;
refflg=vname(_[seqno]);
output;
end;
keep seqno refflg updtcoln;
run;
Please try the below code
data have;
input (Viewnm tablenam thrcolname updtcoln flg1 upflg2 crflg3 qrflg4)($);
datalines;
Nm tbr1 accno acrnbr y n n n
Nm2 tbr2 accno crmnbr n n y n
Mn3 tbr2 accno crmnrcln n y n n
Nm4 tbr2 enitynr entynbr n n n y
;
proc sort data=have;
by tablenam;
run;
data want;
set have;
by tablenam;
retain seqno;
if first.tablenam then seqno=1;
else seqno+1;
run;
proc sort data=want;
by seqno ;
run;
data want2;
set want;
by seqno;
array vars(*) $ flg1 upflg2 crflg3 qrflg4;
do i = 1 to dim(vars);
if _n_=i then refflg=vname(vars(i));
end;
keep seqno refflg updtcoln;
run;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.