BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HabAM
Quartz | Level 8

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

HabAM
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

6 REPLIES 6
ballardw
Super User

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));

Haikuo
Onyx | Level 15

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;

 

Kurt_Bremser
Super User

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.

HabAM
Quartz | Level 8

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.

HabAM
Tom
Super User Tom
Super User

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');
ChrisNZ
Tourmaline | Level 20

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-variablevalue <, symbol-table>);

 

The link you point to shows how to format values with function put().

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1274 views
  • 2 likes
  • 6 in conversation