Date: Mon, 18 Jan 2010 14:52:55 -0600 Reply-To: Joe Matise Sender: "SAS(r) Discussion" From: Joe Matise Subject: Re: Creating Matrix Array Comments: To: Mike Green In-Reply-To: <201001181822.o0IBnv4r024874@malibu.cc.uga.edu> Content-Type: text/plain; charset=ISO-8859-1 One data-independent way would be to make it a single column, then transpose it. data start; format drugids \$100.; input PERSONID DRUGIDS \$ LENGTH; datalines; 12 01411 4 12 01687-04337 14 12 01891 8 12 00688-01891-04337 6 ;;;; run; data mid; set start; keep obsnum personid drugid length dummy; obsnum=_n_; do _t = 1 to countc(drugids,'-')+1; drugid = scan(drugids,_t,'-'); dummy=1; output; end; run; proc sort data=mid; by personid obsnum; run; proc transpose data=mid out=final; by personid obsnum length; var dummy; id drugid; run; Then if you want 0 instead of missing, you can apply that on the back end. -Joe On Mon, Jan 18, 2010 at 12:22 PM, Mike Green wrote: > Hi, > > I have data that looks like the following: > > PERSONID DRUGIDS LENGTH > > 12 01411 4 > 12 01687-04337 14 > 12 01891 8 > 12 00688-01891-04337 6 > > The DRUGIDS variable is an combination of individual drug ids. There is a > possible long list of drug ids. Say the list only contained 6 drugs, I > need the data to be as follows. > > PERSONID 00688 1411 01687 01891 04337 05463 LENGTH > 12 0 1 0 0 0 0 4 > 12 0 0 1 0 1 0 14 > 12 0 0 0 1 0 0 8 > 12 1 0 0 1 1 0 6 > > I am thinking I need to turn DRUGIDS into an array for each observation. > Then create an array of zeros for the complete list of drugs. Then do some > sort of loop to change the 1's to 0's for the drugs in the DRUGIDS array > for each observation. > > I'd appreciate any help you could give. > > Regards, > > Mike >

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