BookmarkSubscribeRSS Feed
Shirin
Obsidian | Level 7

Hello,

I am using the SAS comma12. format. However some values have decimal points and some don't.

I would like to see two decimal places for those who have decimals and no demilas for those who don't.

For example, I would like to see:

12,987.23

365

45,525

145.60

If I change the format to comma12.2 then I get values like 365.00 which I don't want, and if I keep it as comma12. then I lose the decimals!

Any help would be greatly appreciated.

Thank you Smiley Happy

1 REPLY 1
Tom
Super User Tom
Super User

If you really want to do that I think you probably need to write your function.

See:  Using a Function to Format Values

Or you could use code to build your own string in a datastep and print that instead.

if num = int(num) then text=put(num,comma12.);

else text=put(num,comma12.2);

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 3570 views
  • 0 likes
  • 2 in conversation