SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
nid197
Obsidian | Level 7
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
PeterClemmensen
Tourmaline | Level 20

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

PeterClemmensen
Tourmaline | Level 20

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;
nid197
Obsidian | Level 7
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
nid197
Obsidian | Level 7
Seq no is again a new variable which i want to create based on first.value of table name and view name
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 944 views
  • 0 likes
  • 3 in conversation