Date: Wed, 15 Sep 2004 17:06:20 -0700
Reply-To: "Terjeson, Mark" <TERJEM@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <TERJEM@DSHS.WA.GOV>
Subject: Re: dataset list
Content-Type: text/plain
Hi,
Here is a sample program I posted back in January
that needs to do that. So hopefully you can see
where the spaces are computed to determine words:
(you can tally and count spaces instead of '*')
e.g.
WrdCount = length("&yourlist") - length(compress("&yourlist",' ')) + 1;
of course you kinda need to know if there is just one space
between words. If more than one space between, you can use
functions such as compbl() to get it down to one space between
and then compute the count as shown above.
data aa;
input category $ counts perc;
cards;
a 1 0.1
b 4 0.4
c 2 0.2
d 3 0.3
;
run;
* make list of categories and list of counts;
proc sql noprint;
select category into :catlist separted by '*'
from aa;
select counts into :cntslist separted by '*'
from aa;
quit;
%let catlist=&catlist; * trim trailing spaces for v6.x & v8.x ;
%let cntslist=&cntslist; * trim trailing spaces for v6.x & v8.x ;
%put catlist is >&catlist<;
%put cntslist is >&cntslist<;
* get number of categories dynamically ;
data _null_;
CatCount = length("&catlist") - length(compress("&catlist",'*')) + 1;
call symput("CatCount",CatCount);
run;
%let CatCount=&CatCount; * trim trailing spaces for v6.x & v8.x ;
%put CatCount is >&CatCount<;
* initialize bb ;
proc delete data=bb;
run;
* loop through categories ;
%macro do_cats;
%do i_ = 1 %to &CatCount;
%let cat=%scan(&catlist,&i_,*);
%put the cat is >&cat<;
%let count=%scan(&cntslist,&i_,*);
%put the count is >&count<;
proc surveyselect data=aa method=srs
samsize=%eval(&count * 10) out=bb&i_;
where category="&cat";
proc append base=bb data=bb&i_;
run;
%end;
%mend;
%do_cats;
Hope this is helpful,
Mark Terjeson
Reporting, Analysis, and Procurement Section
Information Services Division
Department of Social and Health Services
State of Washington
mailto:terjem@dshs.wa.gov
-----Original Message-----
From: Yufeng Liu [mailto:charlesyufengliu@YAHOO.COM]
Sent: Wednesday, September 15, 2004 4:36 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: dataset list
Somehow it looks like perl.
Is there an easy way to know the number of words in a string?
Yufeng
"Huang, Ya" <yhuang@AMYLIN.COM> wrote:
For whom macro is not a favorite tool, here is a data step
solution. Just for fun:
%let dlst=a b c d;
data _null_;
length doit $3000;
doit=tranwrd(trim(tranwrd(' '||trim(tranwrd(compbl("&dlst")
||' ',' ','; ')),' ','proc sort data=')),';','; by year; run;');
call symput('doit',trim(doit));
run;
options symbolgen;
&doit;
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com