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 (April 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 4 Apr 2006 19:05:49 +0000
Reply-To:   iw1junk@COMCAST.NET
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Ian Whitlock <iw1junk@COMCAST.NET>
Subject:   Array:Multiple obs into One obs. by PTID
Comments:   cc: "jingtailan@gmail.com" <jingtailan@GMAIL.COM>

jingtail,

Don't forget

proc sql ; select ptid , max(slcond1 = 9) as scar , max(slcond1 = 10) as str , max(slcond1 = 11) as conj , max(slcond1 = 12) as oasa , max(slcond1 = 13) as extad from have group by ptid ; quit ;

and method 3 can be improved to one step

data Objective ( drop = slcond1 ) ; array w(9:13) SCAR STR CONJ OASA EXTAD; do slcond1 = 9 to 13 ; w(slcond1) = 0 ; end ; do until (last.ptid); set have; by ptid; if SLCOND1 in (9:13) then w(SLCOND1) = 1; end; run;

Ian Whitlock ================== Date: Mon, 3 Apr 2006 11:24:45 -0700 Reply-To: "jingtailan@gmail.com" <jingtailan@GMAIL.COM> Sender: "SAS(r) Discussion" From: "jingtailan@gmail.com" <jingtailan@GMAIL.COM> Organization: http://groups.google.com Subject: Array:Multiple obs into One obs. by PTID Comments: To: sas-l Content-Type: text/plain; charset="iso-8859-1" Dear all: Yesterday I posted a question on how to consolidate multiple observations into one observation by PTID. thank you for all your input and hints. Howard , "Data_Null_", Toby and David. I post all methods which i am aware of and hope you will learn it should there is a need. =============================================================== ORIGINAL DATA: data have ; infile cards ; input PTID SLCOND1 @@; cards ; 101 9 101 10 101 13 102 12 102 11 103 9 104 0 ; run; ============================================================== METHOD1:

data OBJECTIVE; set have; by ptid ; if slcond1 = '9' then scar = 1; else scar=0; if slcond1 = '10' then str = 1; else str= 0; if slcond1 = '11' then conj = 1; else conj= 0; if slcond1 = '12' then oasa = 1; else oasa=0; if slcond1 = '13' then extad = 1; else extad= 0; output objective; run;

proc means data=objective noprint; var scar str conj oasa extad; by ptid ; output out=objective1drop= _freq_ _type_) max= scar str conj oasa extad; run;

============================================================== METHOD2: data zeros; array _s(9:13) SCAR STR CONJ OASA EXTAD (5*0); output; run; data zhave(drop=slcond1); array _s(9:13) SCAR STR CONJ OASA EXTAD; point = 1; set zeros point=point; do until(last.ptid); set have; by ptid; if slcond1 then _s(SLCOND1) = 1; end; run; ======================================================== METHOD3: data Objective; array w(9:13) SCAR STR CONJ OASA EXTAD; do until (last.ptid); set have; by ptid; if SLCOND1 in (9-13) then w(SLCOND1) = 1; end; run; Data prep ( drop = I ) ; set objective ; array Nums (*) _numeric_ ; Do I = 1 to Dim(Nums) ; if ( Nums(I)=.) then Nums(I) = 0 ; end ; run ;


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