BookmarkSubscribeRSS Feed
GregINGov
Calcite | Level 5

I need to add leading zero to any number under 10.

data lat;

set clovis_data;

  latdeg1=int(latitude);

  latdeg2=int((latitude-latdeg1)*60);

  latdeg3=round((((latitude-latdeg1)*60)-latdeg2)*60);

run;

I need to add leading zero to any number under 10 for Latdeg2 and Latdeg3.

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You can use the format Z2. to make the values appear with a leading zero (or some version of the Zw.d format)

Or you can turn them into character variables and concatenate a zero before the actual value if it is less than 10.

Of the two choices, I prefer the first in most cases, which leaves the number as a numeric variable

--
Paige Miller
GregINGov
Calcite | Level 5

so in format Z2 I  can make just the number under 10 with a leading zero?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, if you have a 0 preceding a number like: 02, its not really a number as such.  So the number there is 2.  If you want to display that with a preceding 0 then you have two options - apply a format Z2. to that variable - or put the number into Z2 and store it in a character variable.  There are plusses and minus to each approach.

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
  • 5 replies
  • 1087 views
  • 9 likes
  • 5 in conversation