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
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