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 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 12 Apr 2004 21:35:52 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: Refering to part of a variable name in a datastepprocedure

Of course generalizing Jack's method to also do February, March, etc. will get messy.

It is not a good idea to embed data (such as time indices) into variable names. That is especially true when the indices are nested (months within years, etc.).

On Mon, 12 Apr 2004 17:44:08 -0600, Jack Hamilton <JackHamilton@FIRSTHEALTH.COM> wrote:

>There's no "automatic" way to do that, unless by some chance the >variables are already stored in the correct logical order in the program >data vector (unlikely). > >You could use PROC SQL to create a macro varaible containing the names >of the variables you want. > >===== >data test; > retain Y1977_01_1 0. Y1978_02_1 1. Y1979_01_1 2. Y1979_02_1 3. > Y1980_01_1 4. Y1981_03_1 5. Y1990_02_1 6.; > /* Sum of 01's is 0 + 2 + 4 = 6 */ > > output; > >run; > >%global vars01; > >proc sql noprint; > > select name > into :vars01 separated by ', ' > from dictionary.columns > where libname = 'WORK' > and memname = 'TEST' > and memtype = 'DATA' > and substr(name, 7, 2) = '01' > and name eqt 'Y'; > >quit; > >data _null_; > > set test; > > result = sum(&VARS01.); > > put result=; > >*****; run; >===== > >prints > > RESULT=6 > >You might need to add additional conditions to the WHERE clause, >depending on the names of the other variables in your data set. > >Incidentally, there are data steps, and there are procedures, but there >are not "dataset proceedures". > > > >-- >JackHamilton@FirstHealth.com >Manager, Technical Development >Metrics Department, First Health >West Sacramento, California USA > >>>> "Pradeep Kurukulasuriya" <pradeep.kurukulasuriya@YALE.EDU> >04/12/2004 4:23 PM >>> >Hello: > >I hope someone will be able to help me with question I have regarding >refering to part of a set of variable names in a datastep proceedure. > >That is, suppose I had the following variables: > >Y1977_01_1 Y1978_02_1....Y1990_12_1 (i.e. variable names that >refer to months in particular years from 1977-1990) and I wanted to >get >the means for January, how I can refer to the _01_ part in the >variable >name? > >I know that something like: > >AVGRAIN=mean(of yd:) -- will get me the means of all the variables >beginning with YD...but what if I want to restrct it to only those >which >contain _01_ (in the middle of the variable name)? > >Many thanks! > >Pradeep


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