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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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