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
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
On Mon, 12 Apr 2004 17:44:08 -0600, Jack Hamilton
>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.
> 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 */
>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';
> set test;
> result = sum(&VARS01.);
> put result=;
>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".
>Manager, Technical Development
>Metrics Department, First Health
>West Sacramento, California USA
>>>> "Pradeep Kurukulasuriya" <pradeep.kurukulasuriya@YALE.EDU>
>04/12/2004 4:23 PM >>>
>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
>the means for January, how I can refer to the _01_ part in the
>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
>contain _01_ (in the middle of the variable name)?