From: maverick2 on
I need to use proc sql into function OR call symput to define a macro
variable. But this has to be done within a macro. So the macro
variable being created has a macro parameter within it. I am unable to
do this. Can this be done by any other method?

%macro test (ds1, ds2, idno);

data &ds1.;
set &ds2.;
if <some condition>;
run;

data _null_;
set &ds2.;
if _n_ = 1 then do;
call symput ('rec&idno',var1);
end;
run;


OR

proc sql;

select var1 into: rec&idno
from &ds2.
where var2 = 1; /* var2 = _n_ in &ds2.*/

quit;

%mend;

%test (one, two, 10);

%test (three, four, 40);


Idea is to get macro variable rec10, rec40, etc. Obviously call symput
and into function are not working, is there any way around this to
define macro variables rec10, rec40 within the macro test?
From: Reeza on
On Apr 21, 9:06 am, maverick2 <phekuch...(a)gmail.com> wrote:
> I need to use proc sql into function OR call symput to define a macro
> variable. But this has to be done within a macro. So the macro
> variable being created has a macro parameter within it. I am unable to
> do this. Can this be done by any other method?
>
> %macro test (ds1, ds2, idno);
>
>        data &ds1.;
>             set &ds2.;
>             if <some condition>;
>         run;
>
>   data _null_;
>      set &ds2.;
>      if _n_ = 1 then do;
>          call symput ('rec&idno',var1);
>      end;
>   run;
>
> OR
>
> proc sql;
>
>         select var1 into: rec&idno
>         from &ds2.
>         where var2 = 1;      /* var2 = _n_ in &ds2.*/
>
> quit;
>
> %mend;
>
> %test (one, two, 10);
>
> %test (three, four, 40);
>
> Idea is to get macro variable rec10, rec40, etc. Obviously call symput
> and into function are not working, is there any way around this to
> define macro variables rec10, rec40 within the macro test

I don't think there's any issues with assigning variables in a macro.
Call symput ('rec&idno',var1); may need to be modified in the macro
statement is my guess.
Your probably creating a variable called 'rec 10' rather than
rec10 so when you try and resolve it you get an error.

Try something like call symput('rec'||left(&idno), var1);
HTH,
Reeza
From: maverick2 on
On Apr 21, 9:20 am, Reeza <fkhurs...(a)hotmail.com> wrote:
> On Apr 21, 9:06 am, maverick2 <phekuch...(a)gmail.com> wrote:
>
>
>
>
>
> > I need to use proc sql into function OR call symput to define a macro
> > variable. But this has to be done within a macro. So the macro
> > variable being created has a macro parameter within it. I am unable to
> > do this. Can this be done by any other method?
>
> > %macro test (ds1, ds2, idno);
>
> >        data &ds1.;
> >             set &ds2.;
> >             if <some condition>;
> >         run;
>
> >   data _null_;
> >      set &ds2.;
> >      if _n_ = 1 then do;
> >          call symput ('rec&idno',var1);
> >      end;
> >   run;
>
> > OR
>
> > proc sql;
>
> >         select var1 into: rec&idno
> >         from &ds2.
> >         where var2 = 1;      /* var2 = _n_ in &ds2.*/
>
> > quit;
>
> > %mend;
>
> > %test (one, two, 10);
>
> > %test (three, four, 40);
>
> > Idea is to get macro variable rec10, rec40, etc. Obviously call symput
> > and into function are not working, is there any way around this to
> > define macro variables rec10, rec40 within the macro test
>
> I don't think there's any issues with assigning variables in a macro.
> Call symput ('rec&idno',var1); may need to be modified in the macro
> statement is my guess.
> Your probably creating a variable called 'rec     10' rather than
> rec10 so when you try and resolve it you get an error.
>
> Try something like call symput('rec'||left(&idno), var1);
> HTH,
> Reeza- Hide quoted text -
>
> - Show quoted text -

hi Reeza,

I tried your method and it works as in does not give any error
messages in the log, but when I do
%put &rec10;

it says that the macro variable is unresolved. It should give the
value of var1 if it is working.
From: Reeza on
On Apr 21, 9:36 am, maverick2 <phekuch...(a)gmail.com> wrote:
> On Apr 21, 9:20 am, Reeza <fkhurs...(a)hotmail.com> wrote:
>
>
>
>
>
> > On Apr 21, 9:06 am, maverick2 <phekuch...(a)gmail.com> wrote:
>
> > > I need to use proc sql into function OR call symput to define a macro
> > > variable. But this has to be done within a macro. So the macro
> > > variable being created has a macro parameter within it. I am unable to
> > > do this. Can this be done by any other method?
>
> > > %macro test (ds1, ds2, idno);
>
> > >        data &ds1.;
> > >             set &ds2.;
> > >             if <some condition>;
> > >         run;
>
> > >   data _null_;
> > >      set &ds2.;
> > >      if _n_ = 1 then do;
> > >          call symput ('rec&idno',var1);
> > >      end;
> > >   run;
>
> > > OR
>
> > > proc sql;
>
> > >         select var1 into: rec&idno
> > >         from &ds2.
> > >         where var2 = 1;      /* var2 = _n_ in &ds2.*/
>
> > > quit;
>
> > > %mend;
>
> > > %test (one, two, 10);
>
> > > %test (three, four, 40);
>
> > > Idea is to get macro variable rec10, rec40, etc. Obviously call symput
> > > and into function are not working, is there any way around this to
> > > define macro variables rec10, rec40 within the macro test
>
> > I don't think there's any issues with assigning variables in a macro.
> > Call symput ('rec&idno',var1); may need to be modified in the macro
> > statement is my guess.
> > Your probably creating a variable called 'rec     10' rather than
> > rec10 so when you try and resolve it you get an error.
>
> > Try something like call symput('rec'||left(&idno), var1);
> > HTH,
> > Reeza- Hide quoted text -
>
> > - Show quoted text -
>
> hi Reeza,
>
> I tried your method and it works as in does not give any error
> messages in the log, but when I do
> %put &rec10;
>
> it says that the macro variable is unresolved. It should give the
> value of var1 if it is working.- Hide quoted text -
>
> - Show quoted text -

Two possible things I can think of without testing...

One where is your put statement?

If in the data null you need to use symget instead.
Or if outside macro, the macro variable is a local macro variable to
the macro....try resolving in the macro, but outside of datastep.

There's somewhere in SAS that lists all the macro variables and their
scope, but where I don't recall.
I'm also assuming you have either the data steps or the proc sql not
both.
From: montura on
proc SQL will create the macro variable.
Get rid of the "&" after the into statement.

 | 
Pages: 1
Prev: filling in the gaps
Next: Clear All