From: Arthur Tabachneck on
Francogrex,

Again, I'm re-posting your request over on the listserv, as there are
quite a few there who are more expert in SAS macros than myself.

Are you only asking if the following can be accomplished?:

%macro one;
data _null_;
do i=1 to 10;
put i;
end;
run;
%mend one;
%one

Art
-------------
On Jul 26, 5:38 am, Francogrex <fra...(a)grex.org> wrote:
> On Jul 26, 12:26 am, Arthur Tabachneck <art...(a)netscape.net> wrote:
>
> > francogrex,
>
> > First, as you can see below, another SAS-L member responded to your
> > original post over on the listserv version of sas-l.
>
> > Second, yes, you can definitely do the things you described and can
> > even use proc fcmp to simply create functions that make it quite easy.
>
> > Ian is definitely more expert in SAS macros than I am, thus I'll leave
> > it to him to show you examples.
>
> Thanks Art, your response and Ian's were informative. Actully while
> digging and trying the first example I gave, can be done like this:
> %let WHILST=%STR(DO WHILE);
> data _null_;
>     i=0;
>     &WHILST (i < 10);
>     put i=;
>     i=i+1;
>     END;
> RUN;
>
> It was a rather simple example.
>
> What I wanted to know (and it's just out of curiosity for the time
> being) whether the language of SAS through the use of Macros can be
> extensible and modifiable and to what extent. For example would there
> be a problem to have this form below run well in SAS:
> data _null_;
>     {For i -> 1:10
>     print i}
> RUN;
>
> and has anyone done this (added a syntax layer to SAS).
> I'll try to read a little bit more on SAS macros and if anyone has
> more info to share here would be welcome of course.

From: Francogrex on
On Jul 26, 1:49 pm, Arthur Tabachneck <art...(a)netscape.net> wrote:
> Francogrex,
>
> Again, I'm re-posting your request over on the listserv, as there are
> quite a few there who are more expert in SAS macros than myself.
>
> Are you only asking if the following can be accomplished?:
>
> %macro one;
>   data _null_;
>     do i=1 to 10;
>       put i;
>     end;
>   run;
> %mend one;
> %one

Hi Art, thanks for forwarding to the list. I know that one can use
"do" for iteration but that's not what I'm after; What I would like to
know is whether one is able to add a syntax layer to SAS somehow, so
such example expression as it is syntaxed:
{For i -> 1:10
print i}
become runnable in one's SAS.
From: Arthur Tabachneck on
Francogrex,

The answer again is yes but, as I don't have access to SAS 9.2, I'll
have to leave showing you how to do it to someone else. I'm pretty
sure that proc fcmp could easily do what you ask.

Art
On Jul 26, 9:15 am, Francogrex <fra...(a)grex.org> wrote:
> On Jul 26, 1:49 pm, Arthur Tabachneck <art...(a)netscape.net> wrote:
>
> > Francogrex,
>
> > Again, I'm re-posting your request over on the listserv, as there are
> > quite a few there who are more expert in SAS macros than myself.
>
> > Are you only asking if the following can be accomplished?:
>
> > %macro one;
> >   data _null_;
> >     do i=1 to 10;
> >       put i;
> >     end;
> >   run;
> > %mend one;
> > %one
>
> Hi Art, thanks for forwarding to the list. I know that one can use
> "do" for iteration but that's not what I'm after; What I would like to
> know is whether one is able to add a syntax layer to SAS somehow, so
> such example expression as it is syntaxed:
> {For i -> 1:10
>     print i}
> become runnable in one's SAS.

From: francogrex on
Dear Art I found the answer of Chang on SAS-L, this is exactly what I'm
looking for; please thank him a lot from me since I cannot post to that
list. Indeed although a little complicated, SAS does have a very powerful
macros system and if one wants, it wouldn't be that difficult to build a
new layer language on top of SAS.

ANSWER FROM SAS-L:
===================================================================
Date: Mon, 26 Jul 2010 14:15:47 -0400
Reply-To: Chang Chung <chang_y_chung(a)HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L(a)LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung(a)HOTMAIL.COM>
Subject: Re: SAS macros
Comments: To: Arthur Tabachneck <art297(a)NETSCAPE.NET>


Hi, Francogrex:

The answer is no, since you cannot overload operators or certain symbols
(like macro triggers). But for simple cases, you can "fake" a new
statement of your own by using the statement macros. You can also pass the
entire arguments into a macro, so that you can parse them and generate
code yourself, as shown below.

Cheers, Chang

options implmac;
%macro for/parmbuff stmt;
%local dlm iter start finish cmd arg;
%let dlm = (){}:->%str( );
%let iter = %scan(&syspbuff,1,&dlm);
%let start = %scan(&syspbuff,2,&dlm);
%let finish= %scan(&syspbuff,3,&dlm);
%let cmd = %scan(&syspbuff,4,&dlm);
%let arg = %scan(&syspbuff,5,&dlm);
%if (&cmd ^= print) %then %return;
do &iter = &start to &finish;
put &arg;
end;
%mend for;
data _null_;
for( i -> 1:10 {
print i
});
run;
/* on log
1
2
3
4
5
6
7
8
9
10