BookmarkSubscribeRSS Feed
smitalpatel
Calcite | Level 5

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.

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Astounding
PROC Star

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 2625 views
  • 1 like
  • 3 in conversation