- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I'm using a macro symputx statement to output needed values that store so I can use them later in my program.
I have this code:
data maxall;
set maxall0;
by tx descending aval;
if _n_ = 1 then call symputx("n"||tx,strip(put(aval,best.)));
if _n_ = 1 then call symputx("m"||tx,cnsr1);
run;
%put &nA &nB &nC &nD &nE &nF &nG &nT;
%put &mA &mB &mC &mD &mE &mF &mG &mT;
All of the cnsr1 values are populated with character values. Macro variables starting with 'n' are resolving fine. However, only the first macro variable beginning with 'm' is resolving. I am getting errors like this: 'WARNING: Apparent symbolic reference MB not resolved.'
I'm not sure why I'm getting this error. Does anyone see any ideas on what might be happening?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why do you have if _n_=1 if you want multiple macro variables? It would only create a macro variable for the first record and no others.
Try removing the IF condition and see if you get what you want.
I would also recommend the CATT function instead of || since it doesn't deal with spaces the same way and you can get some issues with that.
I am guessing though, Since we don't really know what you're trying to do overall (can't see the source data) its hard to say what else is needed.
@jenim514 wrote:
Hi all,
I'm using a macro symputx statement to output needed values that store so I can use them later in my program.
I have this code:
data maxall; set maxall0; by tx descending aval; if _n_ = 1 then call symputx("n"||tx,strip(put(aval,best.))); if _n_ = 1 then call symputx("m"||tx,cnsr1); run; %put &nA &nB &nC &nD &nE &nF &nG &nT; %put &mA &mB &mC &mD &mE &mF &mG &mT;
All of the cnsr1 values are populated with character values. Macro variables starting with 'n' are resolving fine. However, only the first macro variable beginning with 'm' is resolving. I am getting errors like this: 'WARNING: Apparent symbolic reference MB not resolved.'
I'm not sure why I'm getting this error. Does anyone see any ideas on what might be happening?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Run this again on a new SAS session, and you'll find that the &n variables are not defined either. They are not created because of the if _n_ = 1 condition, similar to the &m.
What did you want to achieve with the if _n_ = 1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And depending on the further use of those macro variables, it may well turn out that you'd be better off creating dynamic code directly off the dataset with call execute.