BookmarkSubscribeRSS Feed
Melk
Lapis Lazuli | Level 10

I have a dataset that I want to remove the trailing zeros for all decimal numeric variables. Is there any easy way to do this? I used the best and it did not work.

4 REPLIES 4
Shmuel
Garnet | Level 18

Addapt the format of the numeric variables to showm required decimal digits.

Astounding
PROC Star

No, there's no easy way.  If you want to spend a lot of time for a limited result that approximates what you are asking for, here's a program you can fiddle with:

 

proc format;

value nozero 0=' 0' 1=' 1' 2=' 2' 3=' 3' 4=' 4' 5=' 5' 6=' 6' 7=' 7' 8=' 8' 9=' 9' 10='10' 11='11' other=[5.2];

run;

 

data test;

do j=1 to 11 by 0.01;

output;

end;

run;

 

proc print data=test;

format j nozero.;

run;

ballardw
Super User

@Melk wrote:

I have a dataset that I want to remove the trailing zeros for all decimal numeric variables. Is there any easy way to do this? I used the best and it did not work.


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.

 

As it is we are having to guess what "did not work".

Melk
Lapis Lazuli | Level 10

Horrible solution I came up with for this thread, but I just ended up fixing it in the excel format and re-imported..

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 16. 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
  • 4 replies
  • 3705 views
  • 0 likes
  • 4 in conversation