The SAS Output Delivery System and reporting techniques

Using macro stored numbers in report- symput

Posts: 46

Using macro stored numbers in report- symput

I am having difficulty saving a number format in a report. I have reviewed the comments on but I can't get the comma8.2 format to work. 


Objective- Keep the comma, as in - 10,000, when I call the macro for saved numeric value to add to a report.



data _null_;
set data;
call symputx("val",Total,comma8.2);


-tried it also with vvaluex(Total,comma8.2), and didn't work.


Super User
Posts: 13,941

Re: Using macro stored numbers in report- symput

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.


Also the approach you are using will only have the single value for the last record's value of the total variable in the set data.

And since this line

call symputx("val",Total,comma8.2); generates errors

perhaps you want

call symputx("val", Put(Total,comma8.2));

Respected Advisor
Posts: 3,185

Re: Using macro stored numbers in report- symput

[ Edited ]

Macro variable contains STRING/TEXT. It will store whatever you feed to it. if want '10,000', then you need to feed that into it. So while dealing numeric, you can't directly feed its format to macro variable, instead, you may need to convert it first.


data want;
  input num;
  call symputx('val',put(num,comma8.));

%put val=&val;


Super User
Posts: 10,570

Re: Using macro stored numbers in report- symput



SAS does not provide the log out of pure boredom, it's there for a purpose: that you shall look at it and find what's wrong with your code.


And read the documentation of call symputx

Symputx expects a 'g' or 'l' as the third parameter, not a format.


call symputx("val",put(Total,comma8.2),'g');


Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Posts: 46

Re: Using macro stored numbers in report- symput

Posted in reply to KurtBremser

Thank you Kurt.

I know we all like to see the log. I don't see an error on the is a log for the run with your suggestion


512 data _null_;
513 set data1;
514 call symputx('val',put(Total,comma8.2),'g');
515 run;

NOTE: There were 1 observations read from the data set WORK.data1.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds

cpu time 0.00 seconds


It's just not keeping the numeric format with comma separated values.

instead of 10,000 it is displaying 10000.00 Not sure if am explaining the problem proper.


Its true, SAS does not provide the log out of pure problem is with the output.

Super User
Super User
Posts: 8,279

Re: Using macro stored numbers in report- symput

This is not a macro problem.  Your number is large for the width of your format, so SAS took out the comma so it would fit.

10000 is 5 digits

. is 1 digit

00 is 2 digits


Just increase the width of your format.

call symputx('val',put(Total,comma32.2-L),'g');
Ask a Question
Discussion stats
  • 5 replies
  • 1 like
  • 5 in conversation