ODS and Base Reporting

Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!
BookmarkSubscribeRSS Feed
jenim514
Pyrite | Level 9

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!

 

3 REPLIES 3
Reeza
Super User

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!

 


 

Kurt_Bremser
Super User

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?

Kurt_Bremser
Super User

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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1670 views
  • 0 likes
  • 3 in conversation