LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 19 Feb 2009 19:55:06 -0600
Reply-To:     aldi@wustl.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Aldi Kraja <aldi@WUSTL.EDU>
Subject:      Re: need a favor
Comments: To: Joe Matise <snoopy369@GMAIL.COM>, mike <hadsomeraja@GMAIL.COM>
In-Reply-To:  <b7a7fa630902191627q67112fbfsf0f6b967f7012197@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Mike, Joe is right, I missed the duplication on id=2, but for the id=3 it does not matter because there is no match on the other set.

Here is a solution, which means some exercise how to use base SAS. Try it and have fun! :-) data a; input id label $8. ; datalines; 01 fasted 02 fasted 02 meal 03 fasted 03 meal ;run; data b; input id label2; datalines; 01 0 01 1 01 2 02 0 02 1 02 2 02 0 02 1 02 2 ; run;

data a1; set a; count+1; run; data b1; set b; retain count; if label2=0 then count+1; run;

proc sort data=a1; by count; run; proc sort data=b1; by count; run;

data c (drop=count); merge a1 (in=in1) b1 (in=in2); by count; if in1 and in2; run; proc sort data=c; by id label label2; run; proc print data=c; title "My expected set"; run;

Obs id label label2

1 1 fasted 0 2 1 fasted 1 3 1 fasted 2 4 2 fasted 0 5 2 fasted 1 6 2 fasted 2 7 2 meal 0 8 2 meal 1 9 2 meal 2

Aldi

Joe Matise wrote: > That doesn't quite work, because of the overlap in 02 ... gives 5 meals and > 1 fast for id=03 instead of 3 and 3. > > I could think of a few ways to address that, but the first question I > suppose is, how is SAS really supposed to know which line in dataset a > should go to which line in dataset b? In most cases, there should be a > unique relationship somewhere. If your data structure is exactly like the > OP, then maybe you want something where you don't actually deal with both > datasets as a merge, but instead you do a lookup (either a hash, I suppose, > or I'd probably use SQL since that's what I'm more familiar with) to see > which to output. > > One example that works under some conditions (such as the OP): > data a; > input id label $8.; > datalines; > > 01 fasted > 02 fasted > 02 meal > ; > run; > data b; > input id label2; > datalines; > > 01 0 > 01 1 > 01 2 > 02 0 > 02 1 > 02 2 > 02 0 > 02 1 > 02 2 > ; > run; > > > proc sql; > create table c as select distinct a.id,label,label2 from ( > (select * from a) a > , > (select * from b ) b) > where a.id=b.id ; > quit; > > I don't claim that this works for your real data, or anything close to it, > but it should work on the data provided. More details about the real data > would be helpful if this doesn't work for your actual data. > > -Joe > > On Thu, Feb 19, 2009 at 5:59 PM, Aldi Kraja <aldi@wustl.edu> wrote: > > >> Hi, >> >> Here is the code, which hope it will help to learn SAS: >> >> Best, >> Aldi >> >> data a; >> input id label $8.; >> datalines; >> 01 fasted >> 02 fasted >> 02 meal >> 03 fasted >> 03 meal >> ;run; >> data b; >> input id label2; >> datalines; >> 01 0 >> 01 1 >> 01 2 >> 02 0 >> 02 1 >> 02 2 >> 02 0 >> 02 1 >> 02 2 >> ; >> run; >> proc sort data=a; by id; run; >> proc sort data=b; by id; run; >> data c; >> merge a (in=in1) b (in=in2); >> by id; if in1 and in2; >> run; >> proc print data=c; title "My expected set"; run; >> >> mike wrote: >> >> >>> Hi All, >>> >>> I have two data sets >>> >>> id label >>> >>> 01 fasted >>> 02 fasted >>> 02 meal >>> 03 fasted >>> 03 meal >>> >>> >>> id label >>> 01 0 >>> 01 1 >>> 01 2 >>> 02 0 >>> 02 1 >>> 02 2 >>> 02 0 >>> 02 1 >>> 02 2 >>> >>> I need a dataset like this >>> 01 fasted 0 >>> 01 fasted 1 >>> 01 fasted 2 >>> 02 fasted 0 >>> 02 fasted 1 >>> 02 fasted 2 >>> 02 meal 0 >>> 02 meal 1 >>> 02 meal 2 >>> >>> can someone help me out please in this issue? >>> >>> >>> >> -- >> >>

-- -------------------------------------------------------------------------------- Aldi T. Kraja, DSc, PhD aldi@dsgmail.wustl.edu Research Assistant Professor of Genetics Division of Statistical Genomics http://dsgweb.wustl.edu/aldi Washington University School of Medicine, Phone:(314)362-2498 4444 Forest Park Blvd., Campus Box 8506 Saint Louis, MO, 63110 Fax: (314)362-4227 _______________________________________________________________________________ The materials contained in this e-mail are private and confidential and are the property of the sender. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying, distribution, or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this e-mail transmission in error, please immediately notify the sender.


Back to: Top of message | Previous page | Main SAS-L page