Help using Base SAS procedures

Regarding decimal points controlling while using put function

Reply
New User
Posts: 1

Regarding decimal points controlling while using put function

In numeric variable, I have numbers with 2 and 3 decimal points. what format can I use to convert them to the character format with same decimal points.

Super User
Super User
Posts: 7,392

Re: Regarding decimal points controlling while using put function

Well, if the numbers are all in one column then you likely have a general format such as best. applied to it.  Set the format explicity that you want:

format <your_variable> 5.3;

This will give the number 5 elements including dot e.g.
42.32

However to  extra zeroes to pad out you use the z format:

format <your_variable> z7.4;

So 42.3 would become:

42.3000

Super User
Posts: 5,069

Re: Regarding decimal points controlling while using put function

As was noted, you don't have to convert them.  You could simply use a format when printing them. 

 

Since your original question asked about converting them to character, you would use a PUT function.

 

newvar = put(oldvar, 8.3);

 

The width that you choose ("8" in this example) must be wide enough to include all characters that will be needed:  digits before the decimal point, digits after, the decimal point itself, and a negative sign if needed.

Ask a Question
Discussion stats
  • 2 replies
  • 243 views
  • 1 like
  • 3 in conversation