Hi all,
I have data like below, I am trying to assign sequential order programmatically so that it will automatically rerun when more visits are there in the data.
Can you help me with how can I give sequential order for this?
data have;
input VISIT $1-30 VISITNUM;
datalines;
Screening 1
Cycle 1 Day 1 8
Cycle 1 Day 15 11
Cycle 2 Day 1 15
Cycle 2 Day 15 16
Cycle 3 Day 1 19
Cycle 3 Day 15 20
Cycle 4 Day 1 22
Cycle 4 Day 15 23
Cycle 5 Day 1 25
Cycle 5 Day 15 28
Cycle 6 Day 1 30
Cycle 6 Day 15 31
Cycle 7 Day 1 33
Cycle 7 Day 15 34
Cycle 8 Day 1 36
Cycle 8 Day 15 37
End of Treatment 197
Safety & Efficacy Follow-up 198
Unsched 208
;
run;
Thanks,
Adithya
My desired output is to create AVISITN in sequential order like below.
data have;
input VISIT $1-30 VISITNUM AVISITN;
datalines;
Screening 1 1
Cycle 1 Day 1 8 4
Cycle 1 Day 15 11 8
Cycle 2 Day 1 15 12
Cycle 2 Day 15 16 16
Cycle 3 Day 1 19 20
Cycle 3 Day 15 20 24
Cycle 4 Day 1 22 28
Cycle 4 Day 15 23 32
Cycle 5 Day 1 25 36
Cycle 5 Day 15 28 40
Cycle 6 Day 1 30 44
Cycle 6 Day 15 31 48
Cycle 7 Day 1 33 52
Cycle 7 Day 15 34 56
Cycle 8 Day 1 36 60
Cycle 8 Day 15 37 64
End of Treatment 197 68
Safety & Efficacy Follow-up 198 72
Unsched 208 76
;
run;
Thanks,
Ad
I guess you are establishing intervals of 4 in AVISITN to allow for inserting new observations that will fall between your current set of observations. (Also, why is the first interval only 3?).
Assuming your new observations will always get integer values for AVISITN, does this mean you can guarantee there will never be more than 3 new observations between any of the current visits?
Why not make your order variable into a number with integers for the cycle, and two decimals for the day within cycle, such as:
Cycle 1 Day 1 1.01
Cycle 1 Day 15 1.15
Cycle 2 Day 1 2.01
Cycle 2 Day 15 2.15
Cycle 3 Day 1 ..
Cycle 3 Day 15 ..
Cycle 4 Day 1 ..
Cycle 4 Day 15 ..
Cycle 5 Day 1 ..
Cycle 5 Day 15 ..
Cycle 6 Day 1 ..
Cycle 6 Day 15 ..
Cycle 7 Day 1 ..
Cycle 7 Day 15 ..
Cycle 8 Day 1 8.01
Cycle 8 Day 15 8.15
End of Treatment 98.0
Safety & Efficacy Follow-up 99.0
Assuming you never have more than one visit on any given day, you will never have duplication, and you will always have room for new visits.
This matches your desired output values for Avisitn for the given input data set:
data want; set have; if _n_=1 then AVISITN=1; else AVISITN = (_n_-1)*4; run;
Please note that when I copy and paste your data step into an editor inconsistent use of TAB characters means that many of the VISITNUM values appear in column 28 leading to a number of incomplete records or invalid data.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.