- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm guessing you want something like this but it's unclear.
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.