BookmarkSubscribeRSS Feed
pp2014
Fluorite | Level 6

I have character field  Var1 = "00001234" I convert the above value from character to numeric as follows: data a; format Var1_new 11.; Var1 = "00001234"; Var1_New = Var1 *1; run; Above example does convert to numeric but keeps Zeros. Also I want to know how to get rid of padded zeros in case of Character Value. So If  have Var1 = "00001234".  I want Var1 = "1234" Thanks

1 REPLY 1
Reeza
Super User

PLEASE format your code when posting.

pp2014 wrote:

Above example does convert to numeric but keeps Zeros.

It doesn't on my system, and you're using implicit conversion which will leave a note in your log.

  Obs       Var1_new      Var1

  1            1234    00001234


Use explicit conversion instead, via the input function  To remove leading zeros but retain as a character variable you can either use regular expressions to remove leading zero's or use put/input.


data a1;

format Var1_new 11.;

Var1 = "00001234";

Var1_New = input(var1, 11.);

var1_Char = put(input(var1, 11.), $11. -l);

run;

proc print data=a1;

run;


   Obs       Var1_new      Var1      Char

   1            1234    00001234    1234


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