Date: Thu, 15 Jan 2004 12:16:59 -0800
Reply-To: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Subject: Re: Assign variables to a new variable based on variable names in
SAS
Hi Chang & V -
I'm confused as usual - did you mean this?
142 data one;
143 a_1995q3 = 1;
144 a_1995q4 = 2;
145 a_1997q1 = 3;
146 a_2003q4 = 5;
147 n = "2003q4";
148 run;
NOTE: The data set WORK.ONE has 1 observations and 5 variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds
149
150 data two;
151 set one;
152 call symput('n', n);
153 new_a = 'a_'||resolve(n);
154 put new_a=;
155 run;
new_a=a_2003q4
NOTE: There were 1 observations read from the data set WORK.ONE.
NOTE: The data set WORK.TWO has 1 observations and 6 variables.
NOTE: DATA statement used:
real time 0.03 seconds
cpu time 0.03 seconds
???
Paul Choate
DDS Data Extraction
(916) 654-2160
-----Original Message-----
From: Chang Y. Chung [mailto:chang_y_chung@HOTMAIL.COM]
Sent: Thursday, January 15, 2004 12:06 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Assign variables to a new variable based on variable names in
SAS
On Thu, 15 Jan 2004 11:02:05 -0800, W M <mwx74@HOTMAIL.COM> wrote:
>I have met the following problem and I need your expert help.
>The variable names in the data set looks like this:
>
>a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n
> Is there a way like
>
>new_a=a_{value of n} ?
>
>Because of the compilation of data step, you cannot do
>
>data new; set old;
>call symput("name", n);
>new_a=a_&n; (wrong !)
>run;
Hi, V,
Following up on Paul (Choate)'s idea, this seems to work. This would serve
as an example of putting and resolving a macro variable in a same data
step for a non-trivial purpose.
Cheers,
Chang
<sasl:code>
data one;
a_1995q3 = 1;
a_1995q4 = 2;
a_1997q1 = 3;
a_2003q4 = 5;
n = "2003q4";
run;
%macro new_a;a_&n.%mend;
data two;
set one;
call symput('n', n);
new_a = %new_a;
put new_a=;
run;
/* on log
new_a=5
*/
</sasl:code>