I am having difficulty saving a number format in a report. I have reviewed the comments on https://communities.sas.com/t5/Base-SAS-Programming/CALL-SYMPUT-vs-CALL-SYMPUTX/td-p/377866 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);
run;
-tried it also with vvaluex(Total,comma8.2), and didn't work.
Thanks
READ.THE.LOG.
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.
Do
call symputx("val",put(Total,comma8.2),'g');
instead.
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: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... 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));
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.));
datalines;
10000
;
run;
%put val=&val;
READ.THE.LOG.
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.
Do
call symputx("val",put(Total,comma8.2),'g');
instead.
Thank you Kurt.
I know we all like to see the log. I don't see an error on the log....here 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 boredom...my problem is with the output.
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');
READ.THE.DOC.
What on earth made you think that
call symputx("val",Total,comma8.2);
was valid syntax?
The documentation shows that the third parameter cannot possibly accept formats.
CALL SYMPUTX(macro-variable, value <, symbol-table>);
The link you point to shows how to format values with function put().
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.