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 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 16 May 2008 12:35:05 -0700
Reply-To:   shankera <shanker_anita@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   shankera <shanker_anita@HOTMAIL.COM>
Organization:   http://groups.google.com
Subject:   Re: Add certain variables across a dataset
Comments:   To: sas-l@uga.edu
Content-Type:   text/plain; charset=ISO-8859-1

On May 16, 1:56 pm, muthia.kachira...@GMAIL.COM (Muthia Kachirayan) wrote: > On Fri, May 16, 2008 at 11:50 AM, shankera <shanker_an...@hotmail.com> > wrote: > > > I have a dataset with 100s of variables, and I want to add ones with > > the suffix "_pending". Is there a way to do it without having to > > write out 30 some variable names? > > Using the vname function of the variable and whether it has > underscore-character in the name, the summation can be done for all > _numeric_ variables in the data set. Instead of underscore, the word, > pending, can be looked as an alternative. > > data new; > input f_pending g_pending l_pending h_pending control; > cards; > 5 56 5 2 7 > 6 2 5 6 52 > 5 5 4 5 78 > 6 5 2 8 9 > 7 5 2 1 7 > ; > run; > data need; > length name $32; > set new; > array nv _numeric_; > do over nv; > name = vname(nv[_i_]); > if indexc(name,'_') then sum = sum(sum, nv[_i_]); > * if index(name,'pending') then sum = sum(sum, nv[_i_]); > end; > run; > proc print data = need; > run; > > Muthia Kachirayan

Thanks! I figured out using similar code.


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