Date: Wed, 26 Oct 2005 07:32:24 -0700
Reply-To: "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Subject: Re: The SUM function
Content-Type: text/plain; charset="us-ascii"
Hi Jason,
Here is one possibility that may
seem a little klunky but it works,
until ya find sumpthin mor elegant.
* build same suffix arglist ;
%macro sumsfx(ds,suffix);
%* handle with or without libref ;
%if %index(&ds,.) eq 0 %then
%do;
%let _lib=work;
%let _ds=&ds;
%end;
%else
%do;
%let _lib=%scan(&ds,1,.);
%let _ds=%scan(&ds,2,.);
%end;
proc sql noprint;
select distinct name into :samesfx separated by ','
from sashelp.vcolumn
where name like "%nrstr(%%)&suffix.";
quit;
%put samesfx var list is >&samesfx<;
%mend;
data sample;
acount=1;
bcount=2;
ccount=3;
dcount=4;
run;
%sumsfx(sample,count); * create same suffix variable list ;
data result;
set sample;
abcdsum = sum(&samesfx);
run;
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investment Group
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
jashby2@GMAIL.COM
Sent: Wednesday, October 26, 2005 6:05 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: The SUM function
Hello folks,
I've seen a handy way to sum all variables with the same prefix.. e.g.
TOTAL = SUM(of qtr:);
where 'qtr' is the prefix. Is there a way to sum all variables with the
same suffix?
Thanks,
Jason
|