From: Joe Matise on
No idea why you'd want to do it that way, but isn't that what SYMGET does?

-Joe

On Fri, Feb 19, 2010 at 8:07 PM, Kirby, Ted <ted.kirby(a)lewin.com> wrote:

> Just out of curiosity, does anyone know why SYMGET works (i.e., increments
> the "newcomplines" variables), but %EVAL does not in the following examples:
>
> FIRST PROGRAM
> data test1;
> %let complines=1;
> newcomplines1=input(symget('complines'),8.)+1;
> call symput ('complines',put(newcomplines1,8.));
> newcomplines2=input(symget('complines'),8.)+1;
> call symput ('complines',put(newcomplines2,8.));
> run;
>
> proc print; title "Test1, using SymGet"; run;
>
> OUTPUT FROM PROC PRINT
> Test1, using SymGet
> Obs newcomplines1 newcomplines2
> 1 2 3
>
>
> SECOND PROGRAM
> data test2;
> %let complines=1;
> newcomplines1=%eval(&complines.+1);
> call symput ('complines',put(newcomplines1,8.));
> newcomplines2=%eval(&complines.+1);
> call symput ('complines',put(newcomplines2,8.));
> run;
> proc print; title 'Test2, using %EVAL'; run;
>
> OUTPUT FROM PROC PRINT
> Test2, using %EVAL
> Obs newcomplines1 newcomplines2
> 1 2 2
>
>
> It appears that somehow SYMGET knows that I have changed the value of the
> "complines" macro variable, but %EVAL does not recognize the change.
>
> The %EVAL program reflects the statement that "The macro variable that CALL
> SYMPUT <changes> cannot be successfully referenced until the DATA step
> containing CALL SYMPUT finishes." (Burlew, M. "SAS Macro Programming Made
> Easy" 1998, SAS Institute, Cary, NC, p. 167). However, the SYMGET code
> seems to get around this particular limitation.
>
>
> ************* IMPORTANT - PLEASE READ ********************
>
> This e-mail, including attachments, may include confidential and/or
> proprietary information, and may be used only by the person or entity to
> which it is addressed. If the reader of this e-mail is not the intended
> recipient or his or her authorized agent, the reader is hereby notified that
> any dissemination, distribution or copying of this e-mail is prohibited. If
> you have received this e-mail in error, please notify the sender by replying
> to this message and delete this e-mail immediately.
>
>
From: Patrick on
Have a look at the following example. I think this will answer your
question.

%let complines=1;
data iter;
do i=1 to 2;
output;
end;
run;
data test1;
set iter;
do i=1 to 2;
newcomplines1=input(symget('complines'),8.)+1;
call symput ('complines',put(newcomplines1,8.));
newcomplines2=input(symget('complines'),8.)+1;
call symput ('complines',put(newcomplines2,8.));
put i= newcomplines2= & " " @;
put "complines=&complines";
end;
run;

%put After Datastep: complines=&complines;

Results in:
i=1 newcomplines2=3 complines=1
i=2 newcomplines2=5 complines=1
i=1 newcomplines2=7 complines=1
i=2 newcomplines2=9 complines=1

After Datastep: complines= 9


HTH
Patrick