07-09-2014 09:40 AM
How do I derive vist numbers for unsheduled labs. If an unsheduled lab happens between visit 1 and visit 2 then visit number for that unscheduled visit shoud be 1.1 and if there are 2 unscheduled visits between visit 1 and visit 2, then first unscheduled visit should be 1.1 and second unscheduled visit should be 1.2. and so on.. The following in the sample data. Column VISITNUM should be derived.
Thanks in advance.
07-09-2014 10:27 AM
Well, that depends on what you specs/team tell you. If it is just sort by date (and what if there are multiple on the same date?), then sort the dataset, retain lstvisit and lstunsch, if unscheduled then visit=lstvisit + lstunsch. It could however be far more complicated than that with applied logic defining visit windows, or other known patterns.
Code for the above:
retain lstvisit lstunsch;
if first.subjid then do;
else if type="UNSCHEDULED" then do;
lstunsch=lstunsch+0.1; /* note I would recommend using 0.01 as there may be more than 10 */
visit=lstvisit + lstunsch;
11-01-2014 10:00 AM
Hi RW9, I am working on a HW exercise similar to the OP. The solution you posted only partialy worked for me, SAS produces the vector lstvist such that if visit is (1, 2, ., .,3, ., 4) then lstvisit is (1, 2, 2, 2, 3, 3, 4), which is a step in the right direction. However, the lstunsch produces a vector of missing values. I have been trying to debug for a while but have had little success, any chance you might know what is going on there? Also, I am assuming that your use of "visit" refers to the OP's use of "visitnum", and "type" refers to "visit".
Message was edited by: Kevin Adams
07-09-2014 10:28 AM
Your narrative and your example don't match. Please restate more precisely.
Subject 101 on 15Mar and 10Apr do not follow the pattern in the narrative.
11-01-2014 11:33 AM
I think this solution should work:
Retain visit_r 0;
If first.subjid Then visit_r = visitnum;
If visit = "Unscheduled" Then visitnum = visit_r + 0.01;
visit_r = visitnum;
For a similar example see http://www.mwsug.org/proceedings/2009/stats/MWSUG-2009-D14.pdf
11-01-2014 11:45 PM
Keep it simple:
if first.subject then visitnum = -1;
visitnum + 0.1;
if VISIT ne "Unscheduled" then visitnum = ceil(visitnum);
05-18-2018 06:31 AM - edited 05-18-2018 06:33 AM
Hi i have one more qus for you. in case Unscheduled visit have in same date 15-mar-11 in your data set present only one Unscheduled visit on that day
above the data is given i want visitno add 1.1 all three subjects how to do remaining after the date as taken 1.2
05-20-2018 12:57 AM
If you want all unscheduled visits on a single day to have the same visit number,then change 2 lines of @PGStats's code:
BY SUBJECT LBDTC
IF FIRST.LBDTC THEN VISITNUM+1;