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 (May 2009, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 29 May 2009 14:41:46 -0400
Reply-To:     msz03@albany.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Zdeb <msz03@ALBANY.EDU>
Subject:      Re: Concatenating variables with same prefix or suffix
Content-Type: text/plain;charset=iso-8859-1

nice !!!

would this work just as well (also ... you need the comma in the variable list for use in any of the CAT functions) ...

proc sql; select name into :namelist separated by ',' from dictionary.columns where libname="<libarary name>" and memname="<datasetname>" and name like "%_xxx"; quit;

-- Mike Zdeb U@Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475

> Doesn't matter... : does anything: > > xxx_: > means all variables that start with xxx_ > > _xxx is harder, you need to do some computations either with arrays: > > array vars _numeric_; > do _n_ = 1 to dim(vars); > if find(vname(vars[_n_]),'_xxx') then concatvar = > cats(concatvar,vars[_n_]); > end; > > or with a macro list, usually using proc sql to generate it. Something > like: > > proc sql; > select name into :namelist separated by ' ' > from dictionary.columns > where libname="<libarary name>" > and memname="<datasetname>" > and find(name,"_xxx") > 0; > quit; > > will do, and then > cats(&namelist) > will give you the result you want. > > I suggest using UPCASE in the proc sql, if you end up going that route, as > the upcase/lowcase of variable names etc. is not alwasy consistent. > > -Joe > > On Fri, May 29, 2009 at 1:24 PM, Sanjeev Kommera <sanjivet2k6@yahoo.co.in>wrote: > >> Thanks Joe, I should have been more clear. example variables will be xxx_ >> and _xxx not col1-col&maxnum >> >> Thanks >> >> --- On *Fri, 29/5/09, Joe Matise <snoopy369@gmail.com>* wrote: >> >> >> From: Joe Matise <snoopy369@gmail.com> >> Subject: Re: Concatenating variables with same prefix or suffix >> To: "Sanjeev Kommera" <sanjivet2k6@yahoo.co.in> >> Cc: SAS-L@listserv.uga.edu >> Date: Friday, 29 May, 2009, 11:41 PM >> >> >> You might want to be a wee bit more specific - like give example data. >> >> In general, yes, there are ways to concatenate variables with similar >> suffix/prefix. >> >> Prefix is easiest: >> >> data test; >> x1=2; >> x2=3; >> x3=4; >> run; >> >> data test2; >> set test; >> x = cats(of x:); >> run; >> >> Suffix usually requires some array manipulation or a proc sql macro call. >> Which makes more sense depends on your data. >> >> -Joe >> >> >> On Fri, May 29, 2009 at 12:51 PM, Sanjeev Kommera <sanjivet2k6@yahoo.co.in<http://in.mc943.mail.yahoo.com/mc/compose?to=sanjivet2k6@yahoo.co.in> >> > wrote: >> >>> Hi, Is there a way we could concatenate variables with either same prefix >>> or suffix in a dataset. (NOT concatenating datasets). >>> >>> Also, did anyone try getting Mean(S. D.) or Min, Max (customized stats) >>> from proc tabulate and would like to share the information. (Nope, not using >>> data _null_ and concatenating, but getting an output from proc tabulate?) >>> >>> Thanks very much. >>> sk >>> >>> >>> Cricket on your mind? Visit the ultimate cricket website. Enter >>> http://beta.cricket.yahoo.com >>> >> >> >> ------------------------------ >> Cricket on your mind? Visit the ultimate cricket website. Enter now!<http://in.rd.yahoo.com/tagline_cricket_1/*http://beta.cricket.yahoo.com> >


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