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 (January 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 20 Jan 2010 18:49:08 +0100
Reply-To:   Daniel Fernández <fdezdan@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Daniel Fernández <fdezdan@GMAIL.COM>
Subject:   Re: Distribute the contents of a variable in others
Comments:   To: Stephane COLAS <scolas@datametric.fr>
In-Reply-To:   <201001201258.o0KBlK7r014579@malibu.cc.uga.edu>
Content-Type:   text/plain; charset=ISO-8859-1

proc sql noprint; select cats('x',max(count(var,',')+1)) into :num from test; quit;

data NEED; set test; Array ax(*)$ x1 - &num.; do i=1 to dim(ax); ax(i) = scan (compress(var),i,','); end; drop i; run;

Daniel Fernandez. Barcelona

2010/1/20 Stephane COLAS <scolas@datametric.fr>: > Hi there > > I'm wondering if someone could propose something to do that in one data > step. > > Assume you have one variable VAR like that "a,b,c,d,e,f" and you want to > distribute the contents in several else variables. > > I thought to that but I stopped on the way to automatically detect the > number of variables to create. The goal is to avoid the generation of > unuseful variables with Array. I thought to use a _temporary_ array but I > don't figure out how to have the good number of final variables after. > > data test; > var="a,b,c,d,e,f";output; > var="a,b,c,d,e,f";output; > run; > > data test; > set test; > > count = count(var,' ')+1; /* Is the number of words in VAR*/ > > Array ax(*) x1-x10; /* Could I specify that the number of variables to > create is the value in the variable COUNT ? */ > do = i 1 to dim(ax); > x(i) = scan (var,i,','); > end; > > /*The TEST table will contain the x8 x9 x10 variables without nothing and I > want to avoid that */ > run; > > Any tips ? > > Stephane. >


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