Date: Fri, 16 May 2008 13:56:14 -0400
Reply-To: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject: Re: Add certain variables across a dataset
In-Reply-To: <845c0bdc-10f5-4669-b611-9110cba8f8f1@m73g2000hsh.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
On Fri, May 16, 2008 at 11:50 AM, shankera <shanker_anita@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
|