BookmarkSubscribeRSS Feed
1239
Calcite | Level 5

Hi,

Please find the below sample dataset. I want for each Test whenever Visit = 1 then Visit_order to be as

   if Visit 1 then Visit_order =  1

   if Visit 14 then Visit_order = 2

   if Visit 28 then Visit_order = 3

and

   if Visit 2 then Visit_order =  4

   if Visit 14 then Visit_order = 5

   if Visit 28 then Visit_order = 6.

Could any please help me in achieving this? I have attached expected output for reference.

data test;

input Test $1 Visit 8.;

datalines;

A 1

A 14

A 28

B 2

B 14

B 28

C 2

C 14

C 28

D 1

D 14

D 28

run;

1 REPLY 1
Ksharp
Super User

Your logic is ambiguous. Why the same visit 14 28 get different visit_order?

data test;
input Test $1 Visit 8.;
datalines;
A 1
A 14
A 28
B 2
B 14
B 28
C 2
C 14
C 28
D 1
D 14
D 28
;
run;
data test;
 set test;
 retain _visit;
 if test ne lag(test) then _visit=visit;
run;
data want(drop=_visit);
 set test;
 select;
  when(_visit=1 and visit=1 ) visit_order=1;
  when(_visit=1 and visit=14) visit_order=2; 
  when(_visit=1 and visit=28) visit_order=3;
  when(_visit=2 and visit=2) visit_order=4;
  when(_visit=2 and visit=14) visit_order=5;
  when(_visit=2 and visit=28) visit_order=6;
  otherwise;
 end;
run;




Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 977 views
  • 0 likes
  • 2 in conversation