BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mounika2
Calcite | Level 5

 

data raw (rename= (visit= ELEMENT));
input pt visit :$13. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening 2017-02-10
101 randomization 2017-02-24
101 treatment 2017-03-05
101 followup 2017-09-23 
102 screening 2017-02-12 
102 randomization 2017-02-22 
102 treatment 2017-03-10 
102 followup 2017-09-20 
run;

Here seseq is taken according to alphebetical order of element
and TAESEQ is given according to order of occurence of element

Want:
pt element seseq TAESEQ
101 screening 4 1 101 randomization 3 2 101 DrugA 1 3 101 followup 2 4 102 screening 4 1 102 randomization 3 2 102 DrugB 1 3 102 followup        2      4

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hope you checked the want2 dataset if you run my code which i shared earlier, the want2 dataset has the expected output.

Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

please try the below code

 

data raw (rename= (visit= ELEMENT));
input pt visit :$13. STDT: is8601da.;
if visit='treatment' then visit='Drug A';
format STDT is8601da.;
datalines;
101 screening 2017-02-10
101 randomization 2017-02-24
101 treatment 2017-03-05
101 followup 2017-09-23 
102 screening 2017-02-12 
102 randomization 2017-02-22 
102 treatment 2017-03-10 
102 followup 2017-09-20 
run;

proc sort data=raw;
by pt element;
run;

data want;
set raw;
by pt element;
retain seseq;
if first.pt then seseq=1;
else seseq+1;
run;

proc sort data=want;
by pt STDT;
run;

data want2;
set want;
by pt stdt;
retain taeseq;
if first.pt then taeseq=1;
else taeseq+1;
run;
Thanks,
Jag
Mounika2
Calcite | Level 5

even i followed the same procedure but wen combining the both i am unable to get the following output

 

pt element seseq TAESEQ
101 screening 4 1 101 randomization 3 2 101 DrugA 1 3 101 followup 2 4 102 screening 4 1 102 randomization 3 2 102 DrugB 1 3 102 followup 2 4
Jagadishkatam
Amethyst | Level 16

Hope you checked the want2 dataset if you run my code which i shared earlier, the want2 dataset has the expected output.

Thanks,
Jag
Mounika2
Calcite | Level 5
Yes!
Thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 609 views
  • 0 likes
  • 2 in conversation