Obsidian | Level 7

## Converting column names to row value with condition

Hi ,
I have a dataset
Viewnm tablenam thrcolname updtcoln flg1 upflg2 crflg3 qrflg4
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

I want to convert this to-

seqno refflg uptcol
1 flg1 acrnbr
1 upflg2 crmnbr
2 crflg3 crmnrcln
3 qrflg4 entynbr

Can anypne pls help
5 REPLIES 5
Tourmaline | Level 20

## Re: Converting column names to row value with condition

I don't follow this logic. Eg how are the seqno determined? Why is Seqno=1 in the first two obs?

Tourmaline | Level 20

## Re: Converting column names to row value with condition

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;``````
Obsidian | Level 7

## Re: Converting column names to row value with condition

Seq 1 in first 2 obs denotes that it is table 1's 1st variable.same is with table2.first variable again starts with 1 2 3
Obsidian | Level 7

## Re: Converting column names to row value with condition

Seq no is again a new variable which i want to create based on first.value of table name and view name
Amethyst | Level 16

## Re: Converting column names to row value with condition

``````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;``````
Thanks,
Jag
Discussion stats
• 5 replies
• 742 views
• 0 likes
• 3 in conversation