DATA Step, Macro, Functions and more

Convert numeric with decimal to character with leading zeros

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 79
Accepted Solution

Convert numeric with decimal to character with leading zeros

I have HRLYEARN which is infiled as 6.2

 

So 14.65

 

but I would like to convert it to an 8-character variable with no decimals ie: '001465'

 

Been trying for way too long at this point but I can't get it to work.


Accepted Solutions
Solution
‎01-26-2018 03:10 PM
Super User
Super User
Posts: 8,264

Re: Convert numeric with decimal to character with leading zeros

Posted in reply to fieldsa83

Do you want to keep the same name? If so you need to rename the old variable.

data want ;
  set have ;
     new =put(HRLYEARN*100,Z8.);
     rename new=HRLYEARN HRLYEARN=old_HRLYEARN ;
run;

View solution in original post


All Replies
Super User
Posts: 2,046

Re: Convert numeric with decimal to character with leading zeros

Posted in reply to fieldsa83
data w;
k=14.65;
k1=compress(put(k,z9.2),'.');
run;
Solution
‎01-26-2018 03:10 PM
Super User
Super User
Posts: 8,264

Re: Convert numeric with decimal to character with leading zeros

Posted in reply to fieldsa83

Do you want to keep the same name? If so you need to rename the old variable.

data want ;
  set have ;
     new =put(HRLYEARN*100,Z8.);
     rename new=HRLYEARN HRLYEARN=old_HRLYEARN ;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 302 views
  • 2 likes
  • 3 in conversation