| Date: | Thu, 16 Mar 2000 11:46:31 -0500 |
| Reply-To: | DOUG CONRAD <dconrad@CICINFO.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | DOUG CONRAD <dconrad@CICINFO.COM> |
| Subject: | Re: ISO flexible macro -Answers/responses |
|
| Content-Type: | text/plain; charset="iso-8859-1" |
|---|
Well that was quick!
Thanks all for your input. I now have what I need.
I haven't tested the responses but I think the modular
"%nwords" macro that Peter C sent me fits a little better for me. Though,
the efficiency of Nancy B's code was humbling. I tried something similar to
it before but couldn't get it to increment but this looks real good. Ron
Fehd's code was, well, a bit scary for me. I wasn't even thinking in that
mode but thanks for the input. Nice to have such variation to problem
solving.
For those of you that would like to have the two solutions that I'm
considering for your own notes here they are.
Peter C's Response;
quote""
change the %do iteration to %while
or count the vars with this %nWords() macro
%macro nWords( vars );
%local i j ;
%let i = 1;
%let j = %scan( &vars, &i, %str( ) );
%do %while( &j ne );
%let i = %eval( 1 + &i );
%let j = %scan( &vars, &i, %str( ) );
%end;
%eval( &i - 1 )
%mend nWords;
You would only need to extend your code
from
%do i=1 %to 8;
to
%do i=1 %to %nWords( &_list2 );
"" endquote of peter's response
Karen B's response:
quote""
What about something like:
%do %while (%scan((&_list2),&i) > 0);
%let _check=%scan((&_list2),&i);
proc freq data=&input noprint;
tables &_check/missing out=__ch1;
run;
%let i=%eval(&i+1);
%end;
" endquote.
Thanks much again.
Doug Conrad
Orig Message:
> Here's a good one for you macro mavens. Your help is appreciated.
>
> I need a loop to scan through a list of vars ( in a %let statement). The
> var in the list becomes a 'tables' var in a proc freq. The vars in the
> %let statement could change so I dont want to hard code the number of vars
> in that list. I do hardcode an 8 ( for the # of vars in the _list2
> statement). I don't like that.
>
> Note :there are other macro vars referenced ( &input &pctfail) that are
> called outside ( so basically dont bother with those issues).
>
> The vars in the list are only numeric. It would be OK to have separate
> lists for numeric and char vars and run each thru a separate loop. I look
> for and format the missings and act on that line depending on its
> occurrence.
>
> *********part of the macro code below *************;
>
> %local _check _list2 i _fmt;
>
> %let _list2=patkey age sysage admday
> m_admsrc m_admtyp m_disp m_gender ;
>
> %do i=1 %to 8;
> %let _check=%scan(&&_list2,&i);
>
> proc freq data=&input noprint;
> tables &_check/missing out=__ch1;
> run;
>
> other code........
>
> %end;
>
> other code.....
>
>
>
> Thanks much in advance.
> Doug Conrad
|