Hi, I retrieved this Q&A from stack-overflow and they discuss the
ability of Macros in certain programming languages to do "meta-
programming". In my understanding the Macro as it is in SAS does not do
this, but is equivalent to so-called functions in other languages. As
you can see from the extract below very few programming languages have
the ability to meta-program and even less by using the so-called Macros.
Am I right then that the definition of a Macro in SAS is different?
==========================================
Extract Q&A:
Question: C++ is probably the most popular language for static
metaprogramming and Java doesn't support it.Are there any other
languages besides C++ that support generative programming (programs that
create programs)? Which ones are the best (for learning, for efficiency,
for maintenance, for embedded systems, whatever)?
Reply: The alternative to template style meta-programming is Macro-style
that you see in various Lisp implementations. I would suggest
downloading Paul Graham's On Lisp and also taking a look at Clojure if
you're interested in a Lisp with macros that runs on the JVM. Macros in
Lisp are much more powerful than C/C++ style and constitute a language
in their own right -- they are meant for meta-programming.
|
|
0
|
|
|
|
Reply
|
franco265 (2)
|
7/25/2010 10:42:16 AM |
|
Since one has the ability to use call execute, dm commands and include
files in SAS, the ability to accomplish at least some level of meta-
programming appears to be rather clear and not just limited to SAS
macros.
Art
-------------
On Jul 25, 6:42=A0am, francogrex <fra...@grex-removethis.com> wrote:
> Hi, I retrieved this Q&A from stack-overflow and they discuss the
> ability of Macros in certain programming languages to do "meta-
> programming". In my understanding the Macro as it is in SAS does not do
> this, but is equivalent to so-called functions in other languages. As
> you can see from the extract below very few programming languages have
> the ability to meta-program and even less by using the so-called Macros.
> Am I right then that the definition of a Macro in SAS is different?
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Extract Q&A:
> Question: C++ is probably the most popular language for static
> metaprogramming and Java doesn't support it.Are there any other
> languages besides C++ that support generative programming (programs that
> create programs)? Which ones are the best (for learning, for efficiency,
> for maintenance, for embedded systems, whatever)?
>
> Reply: The alternative to template style meta-programming is Macro-style
> that you see in various Lisp implementations. I would suggest
> downloading Paul Graham's On Lisp and also taking a look at Clojure if
> you're interested in a Lisp with macros that runs on the JVM. Macros in
> Lisp are much more powerful than C/C++ style and constitute a language
> in their own right -- they are meant for meta-programming.
|
|
0
|
|
|
|
Reply
|
Arthur
|
7/25/2010 1:56:13 PM
|
|
I'm sorry but I don't quite understand. Can you use macros to introduce
new syntax into the language? Can you show me if this can be done:
/* the DO WHILE loop */
data _null_;
i = 1;
DO WHILE (i<10);
put i=;
i=i+1;
END;
run;
/* your implementation of the WHILST loop */
data _null_;
i = 1;
WHILST (i<10);
put i=;
i=i+1;
END;
run;
/* or even introduce something like this? */
data _null_;
x = 1;
UNLESS (x > 5);
Put x=;
run;
Arthur Tabachneck wrote:
>Since one has the ability to use call execute, dm commands and include
>files in SAS, the ability to accomplish at least some level of meta-
>programming appears to be rather clear and not just limited to SAS
>macros.
>
>Art
>-------------
>On Jul 25, 6:42�am, francogrex <fra...@grex-removethis.com> wrote:
>> Hi, I retrieved this Q&A from stack-overflow and they discuss the
>> ability of Macros in certain programming languages to do "meta-
>> programming". In my understanding the Macro as it is in SAS does not do
>> this, but is equivalent to so-called functions in other languages. As
>> you can see from the extract below very few programming languages have
>> the ability to meta-program and even less by using the so-called Macros.
>> Am I right then that the definition of a Macro in SAS is different?
>> ==========================================
>> Extract Q&A:
>> Question: C++ is probably the most popular language for static
>> metaprogramming and Java doesn't support it.Are there any other
>> languages besides C++ that support generative programming (programs that
>> create programs)? Which ones are the best (for learning, for efficiency,
>> for maintenance, for embedded systems, whatever)?
>>
>> Reply: The alternative to template style meta-programming is Macro-style
>> that you see in various Lisp implementations. I would suggest
>> downloading Paul Graham's On Lisp and also taking a look at Clojure if
>> you're interested in a Lisp with macros that runs on the JVM. Macros in
>> Lisp are much more powerful than C/C++ style and constitute a language
>> in their own right -- they are meant for meta-programming.
>
|
|
0
|
|
|
|
Reply
|
francogrex
|
7/25/2010 7:39:01 PM
|
|
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.
Art
--------------
On Jul 25, 3:39=A0pm, francogrex <fra...@grex-removethis.com> wrote:
> I'm sorry but I don't quite understand. Can you use macros to introduce
> new syntax into the language? Can you show me if this can be done:
> /* the DO WHILE loop */
> data _null_;
> =A0 =A0 i =3D 1;
> =A0 =A0 DO WHILE (i<10);
> =A0 =A0 =A0 =A0 put i=3D;
> =A0 =A0 =A0 =A0 i=3Di+1;
> =A0 =A0 =A0 =A0 END;
> run;
>
> /* your implementation of the WHILST loop */
> data _null_;
> =A0 =A0 i =3D 1;
> =A0 =A0 WHILST (i<10);
> =A0 =A0 put i=3D;
> =A0 =A0 i=3Di+1;
> =A0 =A0 END;
> run;
>
> /* or even introduce something like this? */
>
> data _null_;
> =A0 =A0 x =3D 1;
> =A0 =A0 UNLESS (x > 5);
> =A0 =A0 Put x=3D;
> run;
>
>
>
> Arthur Tabachneck wrote:
> >Since one has the ability to use call execute, dm commands and include
> >files in SAS, the ability to accomplish at least some level of meta-
> >programming appears to be rather clear and not just limited to SAS
> >macros.
>
> >Art
> >-------------
> >On Jul 25, 6:42=A0am, francogrex <fra...@grex-removethis.com> wrote:
> >> Hi, I retrieved this Q&A from stack-overflow and they discuss the
> >> ability of Macros in certain programming languages to do "meta-
> >> programming". In my understanding the Macro as it is in SAS does not d=
o
> >> this, but is equivalent to so-called functions in other languages. As
> >> you can see from the extract below very few programming languages have
> >> the ability to meta-program and even less by using the so-called Macro=
s.
> >> Am I right then that the definition of a Macro in SAS is different?
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Extract Q&A:
> >> Question: C++ is probably the most popular language for static
> >> metaprogramming and Java doesn't support it.Are there any other
> >> languages besides C++ that support generative programming (programs th=
at
> >> create programs)? Which ones are the best (for learning, for efficienc=
y,
> >> for maintenance, for embedded systems, whatever)?
>
> >> Reply: The alternative to template style meta-programming is Macro-sty=
le
> >> that you see in various Lisp implementations. I would suggest
> >> downloading Paul Graham's On Lisp and also taking a look at Clojure if
> >> you're interested in a Lisp with macros that runs on the JVM. Macros i=
n
> >> Lisp are much more powerful than C/C++ style and constitute a language
> >> in their own right -- they are meant for meta-programming.- Hide quote=
d text -
>
> - Show quoted text -
On Sun, 25 Jul 2010 15:32:59 -0400, Ian Whitlock <iw1sas@GMAIL.COM>
wrote:
>On Sun, Jul 25, 2010 at 3:25 PM, Ian Whitlock <iw1sas@gmail.com> wrote:
>> francogrex,
>>
>> As Wikipedia defines metaprogramming
>> <http://en.wikipedia.org/wiki/Metaprogramming>,
>>
>> Metaprogramming is the writing of computer programs that write or
>> manipulate other programs (or themselves) as their data, or that
>> do part of the work at compile time that would otherwise be done
>> at runtime. In many cases, this allows programmers to get more
>> done in the same amount of time as they would take to write all
>> the code manually, or it gives programs greater flexibility to
>> efficiently handle new situations without recompilation.
>>
>> In this sense, I would define a programming language in a circular
>> manner as one that can take in data and output programs. So any
>> programming language including SAS can do metaprogramming.
>>
>> However, of particular interest is languages which can manipulate
>> their own programs. Again SAS (without macro) meets this condition
>> because a DATA step can read data and write code that is to be
>> executed with %INCLUDE in the same program. It is the fact that SAS
>> compiles and executes in steps, plus %INLUDE that gives SAS this
>> reflexive ability.
>>
>> SAS macro while another language is closely integrated with SAS and
>> one usually thinks of SAS macros as part of a SAS program. (I don't
>> really see how one can separate the two languages from the point of
>> view as a complete program, although it is very helpful to think of
>> two languages as you write the code for this one program.) The role
>> of SAS macro is to make metaprogramming in SAS much easier. In
>> short SAS macro supports this style of programming while SAS alone
>> provides the ability for the programmer to support this style of
>> programming. Adding macro really supports this style.
>>
>> In languages like LISP and Ruby, it is the language itself that
>> provides the support for the ability to have the program manipulate
>> itself.
>>
>> Is the difference significant? I think the answer is largely in the
>> eye of the beholder. I would say that thinking in this style of
>> programming is far more significant than whether you think of the
>> language as a combination of parts (SAS compiler/parser, macro
>> facility, and executer) or one black box that supports the writing
>> of your code.
>>
>> On the other hand, some might think the SAS institute could provider
>> better support for metaprogramming than already provided by SAS
>> macro.
>>
>> Art, if you have the address, please forward to francogrex.
>>
>> Ian Whitlock
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>>
>>
>> Date: Sun, 25 Jul 2010 06:56:13 -0700
>> From: Arthur Tabachneck <art297@NETSCAPE.NET>
>> Subject: Re: SAS macros
>>
>> Since one has the ability to use call execute, dm commands and include
>> files in SAS, the ability to accomplish at least some level of meta-
>> programming appears to be rather clear and not just limited to SAS
>> macros.
>>
>>
>> Art
>> -------------
>> On Jul 25, 6:42 am, francogrex <fra...@grex-removethis.com> wrote:
>>> Hi, I retrieved this Q&A from stack-overflow and they discuss the
>>> ability of Macros in certain programming languages to do "meta-
>>> programming". In my understanding the Macro as it is in SAS does not do
>>> this, but is equivalent to so-called functions in other languages. As
>>> you can see from the extract below very few programming languages have
>>> the ability to meta-program and even less by using the so-called Macros=
..
>>> Am I right then that the definition of a Macro in SAS is different?
>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>>> Extract Q&A:
>>> Question: C++ is probably the most popular language for static
>>> metaprogramming and Java doesn't support it.Are there any other
>>> languages besides C++ that support generative programming (programs tha=
t
>>> create programs)? Which ones are the best (for learning, for efficiency=
,
>>> for maintenance, for embedded systems, whatever)?
>>>
>>> Reply: The alternative to template style meta-programming is Macro-styl=
e
>>> that you see in various Lisp implementations. I would suggest
>>> downloading Paul Graham's On Lisp and also taking a look at Clojure if
>>> you're interested in a Lisp with macros that runs on the JVM. Macros in
>>> Lisp are much more powerful than C/C++ style and constitute a language
>>> in their own right -- they are meant for meta-programming.
>--
>Ian Whitlock
|
|
0
|
|
|
|
Reply
|
art297 (4237)
|
7/25/2010 10:26:54 PM
|
|
On Jul 26, 12:26=A0am, Arthur Tabachneck <art...@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=3D%STR(DO WHILE);
data _null_;
i=3D0;
&WHILST (i < 10);
put i=3D;
i=3Di+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.
|
|
0
|
|
|
|
Reply
|
Francogrex
|
7/26/2010 9:38:59 AM
|
|
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=3D1 to 10;
put i;
end;
run;
%mend one;
%one
Art
-------------
On Jul 26, 5:38=A0am, Francogrex <fra...@grex.org> wrote:
> On Jul 26, 12:26=A0am, Arthur Tabachneck <art...@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=3D%STR(DO WHILE);
> data _null_;
> =A0 =A0 i=3D0;
> =A0 =A0 &WHILST (i < 10);
> =A0 =A0 put i=3D;
> =A0 =A0 i=3Di+1;
> =A0 =A0 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_;
> =A0 =A0 {For i -> 1:10
> =A0 =A0 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.
|
|
0
|
|
|
|
Reply
|
art297 (4237)
|
7/26/2010 11:49:30 AM
|
|
On Jul 26, 1:49=A0pm, Arthur Tabachneck <art...@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;
> =A0 data _null_;
> =A0 =A0 do i=3D1 to 10;
> =A0 =A0 =A0 put i;
> =A0 =A0 end;
> =A0 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.
|
|
0
|
|
|
|
Reply
|
franco (241)
|
7/26/2010 1:15:06 PM
|
|
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=A0am, Francogrex <fra...@grex.org> wrote:
> On Jul 26, 1:49=A0pm, Arthur Tabachneck <art...@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;
> > =A0 data _null_;
> > =A0 =A0 do i=3D1 to 10;
> > =A0 =A0 =A0 put i;
> > =A0 =A0 end;
> > =A0 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
> =A0 =A0 print i}
> become runnable in one's SAS.
|
|
0
|
|
|
|
Reply
|
art297 (4237)
|
7/26/2010 3:02:57 PM
|
|
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@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: SAS macros
Comments: To: Arthur Tabachneck <art297@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
|
|
0
|
|
|
|
Reply
|
francogrex
|
7/26/2010 7:25:39 PM
|
|
|
8 Replies
244 Views
(page loaded in 0.145 seconds)
Similiar Articles: Macro SAS - counting rows. - comp.soft-sys.sasHi. I=B4m triying to count the number of rows of a table without using the "select count" command but I dont know wich is the command to do this. ... Evaluating Logical Variables in SAS Macro - comp.soft-sys.sas ...I'm wondering if anyone has any experience in how to evaluate logical expressions as part of a Macro of the form. %let FX = (3.851315692 + -0.2046... Regarding SAS Macro - comp.soft-sys.sasHello. Now I am studying for SAS Advanced Programming in SAS 9. ===== 3 Which of the following correctly references the macro named ... Query regarding SAS Macros & ODS - comp.soft-sys.sasHi all, I have a data set of Completely randomized design. I want to use different data sets and display output according to my need. So I use OD... SAS Macro for Adjusted Survival Curves - comp.soft-sys.sas ...Hi, there is a paper (which I have in copy): James Lee, C. Yoshizawa, L. Wilkens, and H.P. Lee (1992): Covariance adjustment of survival curves bas... User written macro or SAS supplied macro ?? - comp.soft-sys.sas ...User written macro or SAS supplied macro ?? - comp.soft-sys.sas ... Tips on writing sas macros - Data Savant Consulting A well-written SAS macro is a very valuable ... Pass a variable as a macro parameter. - comp.soft-sys.sas ...Hi there, I was wondering if anyone could help me with the following. Imagine I have a simple macro that does some text manipulation e.g. %ma... Getting the outcome of a system command into SAS macro variable ...I know that in Unix I can use FILENAME PIPE command then use DATA STEP to read in results of a system command. For example, filename abc PIPE "l... Is this a macro bug??? - comp.soft-sys.sasHi, I have a "loop" macro as follows: /*----- * PROGRAM: loop * DESCRIPTIO... ... Hi, I have a ... What is the option in Macro to display ERROR message if macro ...check for variable existence, if not there put variable in. - comp ... Hi Catima, SYMEXIST checks the existence of macro variables, not the existence of SAS ... 243-29: SAS Macro Programming for Beginners1 Paper 243 -29 SASâ Macro Programming for Beginners Susan J. Slaughter, Avocet Solutions, Davis, CA Lora D. Delwiche, Delwiche Consulting, Winters, CA Statistical Computing Seminar: Introduction to SAS Macro LanguageStatistical Computing Seminars Introduction to SAS Macro Language. You can view movies of this seminar via the links below. Introduction to SAS Macros, Part 1 7/15/2012 8:17:13 PM
|