Date: Thu, 15 Oct 2009 10:41:42 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Getting all The Visits for each one of the subjects
In-Reply-To: <c2192a610910150824m4b9f7ba3sf329d019cbcaac7@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
If you have every possible visit represented on each subject, you don't even
need to use a second visit table. PROC FREQ can do it for you (thanks, data
_null_ ):
Data VS ;
Input Sbj $4. visit $6. Visitnum ;
Datalines ;
1001 week1 1
1001 week2 2
1001 week3 3
1002 week1 1
1003 week2 2
1003 week3 3
1004 week1 1
1004 week2 1
1004 week4 1
1004 week5 1
;
Run;
proc freq data=vs;
tables sbj*visit /sparse out=test;
run;
TEST will have a record for every possible combination of subject and visit,
including combinations that don't occur in the data; and the COUNT variable
will tell you whether or not they occur.
Now, the addition of 'visitnum' makes it slightly more complicated. If that
is not obtainable from visit directly [a substring, for example], then you
may need to do it slightly differently; either two separate runs of PROC
FREQ, one by subj*visit, one subj*visitnum, and then merge by subj (if they
will sort correctly), or (probably easier) merge the visitnums from the
latter dataset on after the fact [or the other way around].
If you did it without a PROC FREQ, you would probably be best off using a
SQL outer join (a many to many merge).
-Joe
On Thu, Oct 15, 2009 at 10:24 AM, SAS_learner <proccontents@gmail.com>wrote:
> Hello all,
>
> What I have is list of all the visits in the study and a VS dataset . Now
> I
> have to compare VS data with the Visit data. in the VS dataset for the Sbj
> =1001 there are two visits (week1 , Week 2 , Week 3) but in the visit
> dataset this guy missed week4 week5 and Subj =1002 has missed week2-
> week5 so I want to final dataset with the all the visits (even the missing
> visits ) like some thing data final
>
> What I am doing is to see how many visits a subject has missed ?
>
> Data VS ;
> Input Sbj $4. visit $6. Visitnum ;
> Datalines ;
> 1001 week1 1
> 1001 week2 2
> 1001 week3 3
> 1002 week1 1
> 1003 week2 2
> 1003 week3 3
> ;
> Run;
>
> Data Visit ;
> Input visit $6. Visitnum ;
> Datalines ;
> week1 1
> week2 2
> week3 3
> week4 4
> week5 5
> ;
> Run;
> *This Code is working if there only one subject but it is working or giving
> me wrong results *;
> Proc Sort data = test ;
> By Visitnum Visit ;
> Run;
>
> Proc Sort Data = Visit ;
> By Visitnum Visit ;
> Run;
>
> Data Visit_map ;
> Merge test Visit ;
> By Visitnum Visit ;
> Run;
>
> *Fianl Dataset structure I thinking I need to check if Subject has missed
> any visits *;
>
> Sub Visit Visitnum all_visit
>
> 1001 week1 1 week1 1
> 1001 week2 2 week2 2
> 1001 week3 3 week3 3
> week4 4
> week5 5
>
> 1002 week1 1 week1 1
> week2 2
> week3 3
> week4 4
> week5 5
> week1 1
> 1003 week2 2 week2 2
> week3 3
> week4 4
> week5 5
> week1 1
> week2 2
> 1003 week3 3 week3 3
> week4 4
> week5 5
>
|