From: rjf2 on
> From: ankur
> Subject: Issue with %let
>
> How do I make a macro variable take value "%let modelvars= " ???
> Following doesn't work
> %let myvar = %let modelvars= ;

uh, why do you want to assign an assignment statement to a macro
variable?

your next problem:

"How can I get this to work?"

&MyVar. value;

%Put note2: MyVar: &%scan(&MyVar.,2, =);

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
From: Joe Matise on
%NRSTR causes the inside &/% to not resolve. For this purpose %NRSTR would
be superior.

-Joe

On Wed, Jan 6, 2010 at 2:13 PM, SAS_learner <proccontents(a)gmail.com> wrote:

> I have suggested try %let myvar = %str(%let modelvars=)
>
> would it work or is there diff between %nrstr() and %str () ??
>
> ---------- Forwarded message ----------
> From: SAS_learner <proccontents(a)gmail.com>
> Date: Wed, Jan 6, 2010 at 9:06 AM
> Subject: Re: Issue with %let
> To: ankur <ankur.bohra(a)gmail.com>
>
>
> try %let myvar = %str(%let modelvars=)
>
> does that work
>
> but why do u want to do it ??
>
>
> On Wed, Jan 6, 2010 at 8:48 AM, ankur <ankur.bohra(a)gmail.com> wrote:
>
> > How do I make a macro variable take value "%let modelvars= " ???
> > Following doesn't work
> > %let myvar = %let modelvars= ;
> >
> > Thanks,
> > Ankur Bohra.
> >
>
From: Ian Whitlock on
Ankur,

You have gotten answers to your question, but the big
question is why you want to do this. If we knew the
problem you wanted to solve that caused you question,
someone would probably give you a much better way to
solve it.

Indirection such as

%let macvar - modelvars ;
%let &macvar = x y z ;
%put &&&macvar ;

can be very useful and is an important pattern for
exporting local variables to an external environment.
However,

%let myvar = %nrstr(%let modelvars =) ;
%unquote(&myvar) x y z ;
%put &modelvars ;

is just very obscure code. In general, macro can be good
for generating SAS code, but it is a very poor language for
generating macro code.

Ian Whitlock
===============

Date: Wed, 6 Jan 2010 08:48:44 -0800
From: ankur <ankur.bohra(a)GMAIL.COM>
Subject: Issue with %let

How do I make a macro variable take value "%let modelvars= " ???
Following doesn't work
%let myvar = %let modelvars= ;

Thanks,
Ankur Bohra.
From: Chang Chung on
On Wed, 6 Jan 2010 16:46:24 -0500, Ian Whitlock <iw1sas(a)GMAIL.COM> wrote:

....
>Indirection such as
>
> %let macvar - modelvars ;
> %let &macvar = x y z ;
> %put &&&macvar ;
>
>can be very useful and is an important pattern for
>exporting local variables to an external environment.
>However,
>
> %let myvar = %nrstr(%let modelvars =) ;
> %unquote(&myvar) x y z ;
> %put &modelvars ;
>
>is just very obscure code. In general, macro can be good
>for generating SAS code, but it is a very poor language for
>generating macro code.
....
Hi,

I agree with Ian that the macro language is poor for generating macro code.

On exporting values to an external environment, there are several
techniques. Most popular seems to be the one Ian mentions. Suppose that your
macro, zero, wants to return a value(0) to the environment, then what you do
is to pass your macro variable *name* to your macro. Your macro, then assign
the return value to the &name. (shown in %zero below). An old timer may
stick to the convention of naming by-name macro parameters starting with an
underscore(_), in order to distinguish them from the usual by-value
parameters.

One may accomplish the same thing using the %global statement inside the
macro (as macro %one below does), but it has been pointed out many, many
times that using the global macro variable for this purpose is not a good
practice and should be avoided.

Many different ways have proposed, then, to avoid the global macros, and one
way was returning a %let statement as a whole, macro quoted, so that it can
be %unquoted in the environment as shown in macro %two below. Richard
Devenezia calls this technique "RESOLVE" and utilizes in his elaborate
%split macro, http://devenezia.com/downloads/sas/macros/index.php?m=split

By the way, the difference between %str() and %nrstr() functions is that the
latter quotes the macro triggers % and &, while the former does not. In some
cases, however, you can find a creative way of using %str() to do what
%nrstr() does, as demonstrated in the macro %three below -- with a warning
though :-(

Below ran on 9.2 (TS1M0) on W32_VSPRO. Hope this helps a bit.

Cheers,
Chang

%*-- using a by-name (not by-value) parameter --*;
%let r=;
%macro zero(_out=);
%let &_out=0;
%mend zero;
%*-- check --*;
%put before: r=&r;
%zero(_out=r)
%put after: r=&r;
%*-- on log
before: r=
after : r=0
--*;

%*-- global macro to return some values. should be avoided --*;
%let r=;
%macro one;
%global r;
%let r= 1;
%mend one;
%*-- check --*;
%put before: r=&r;
%one
%put after : r=&r;
%*-- on log
before: r=
after : r=1
--*;

%*-- return a value without global macros. requires unquoting --*;
%macro two;
%nrstr(%let r=2;)
%mend two;
%*-- check --*;
%symdel r;
%put before: r=&r;
%unquote(%two)
%put after : r=&r;
%*-- on log
WARNING: Apparent symbolic reference R not resolved.
before: r=&r
after : r=2
--*;

%*-- a creative way of using %str() to quote macro triggers --*;
%macro three;
%str(%%l)et r=3;
%mend three;
%symdel r;
%put before: r=&r;
%unquote(%three)
%put r=&r;
From: Ian Whitlock on
Ankur,

It is not clear to me whether the validation is done in the same job
as model building.
If it is the same job then I would have a simple macro

%macro varlist ; x y z %mend varlist ;

Otherwise, I might have

data lib.cntl ;
mvar = "varlist" ;
value = "x y z" ;
run ;

in the model building job and

data _null_ ;
set lib.cntl ;
call symput (mvar, value) ;
run ;

in both jobs.

More in line with your thought one could have.

data _null_ ;
file cntl ;
put '%let varlist = x y z ;' ;
run ;

in the model building job and use %INCLUDE in both jobs.

Ian Whitlock
==============

On Jan 6, 2010, at 6:49 PM, Ankur Bohra wrote:

> Hi,
> Thanks a lot for your responses.
>
> In my project I am building a logistic model. There I develop the
> model in one code. I store model variables in a macro variable i.e.
> %let varlist=v1 v2 v3;
> proc logistic data=x;
> model y = &varlist.;
> and output the model coefficients in a permanent dataset.
>
> I do out of time validation in a different file. Here I am using
> proc score ... however i do not want to update the variable list in
> the out of time validation code. So i need a mechanism to get macro
> variable varlist from development code to validation code. So I
> thought I will create a text file with contents %let varlist=v1 v2
> v3; from within the development code. Hence the query. I realize
> there is a better way to do this however I was trying out this make
> shift arrangement and got stuck!!! Will appreciate if you could help
> me with a cleaner way to do this.
>
> Thanks,
> Ankur Bohra.
>
> On Thu, Jan 7, 2010 at 3:16 AM, Ian Whitlock <iw1sas(a)gmail.com> wrote:
> Ankur,
>
> You have gotten answers to your question, but the big
> question is why you want to do this. If we knew the
> problem you wanted to solve that caused you question,
> someone would probably give you a much better way to
> solve it.
>
> Indirection such as
>
> %let macvar - modelvars ;
> %let &macvar = x y z ;
> %put &&&macvar ;
>
> can be very useful and is an important pattern for
> exporting local variables to an external environment.
> However,
>
> %let myvar = %nrstr(%let modelvars =) ;
> %unquote(&myvar) x y z ;
> %put &modelvars ;
>
> is just very obscure code. In general, macro can be good
> for generating SAS code, but it is a very poor language for
> generating macro code.
>
> Ian Whitlock
> ===============
>
> Date: Wed, 6 Jan 2010 08:48:44 -0800
> From: ankur <ankur.bohra(a)GMAIL.COM>
>
> Subject: Issue with %let
>
> How do I make a macro variable take value "%let modelvars= " ???
> Following doesn't work
> %let myvar = %let modelvars= ;
>
> Thanks,
> Ankur Bohra.
>
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: STDM AE Start and End Reference
Next: Legend problem