BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
andyoey
Calcite | Level 5

Dear community friends,

 

I am having problem in converting a character to numeric and back to character again

The idea is to get only the numbers without the "0" in the beginning

For example, the number is 0012345678901230042 and I want to the new field to result as 12345678901230042

I tried using the following syntax:

 

LEFT(PUT(input(Account_ID,BEST19.0),19.)) end as MainAccountID

 

The result is 12345678901230040 with Character format

Seems the last number is being rounded down by the system

Really appreciate if anyone can give some help

Thanks a lot

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Pleasenote, what I provided was an example to show the logic.  You would of course pass in the dataset which you have (and I don't!) using a set statement.

data want;
  set yourdata;
  account_id=substr(account_id,findc(account_id,"123456789"));
run;

Replace the word yourdata with the dataset name.

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

SAS has a limit to the number of digits in long numbers.  I can remember off the top of my head, but I believe it is 16.  Anyways, if you just want to remove the preceding 0's:

data want;
account_id="0012345678901230042";
account_id=substr(account_id,findc(account_id,"123456789"));
run;
andyoey
Calcite | Level 5

Hi,

Thanks for the feedback

Unfortunately the solution can only affect 1 sample, while there are more than 1000 data with different numbers with the one from my example, such as

00134578919018018

00245819124782933

00011238194719972

I won't be able to specify all the numbers to only exclude the 0 from the begining

Also, I tried your solution and it still take the first "00"

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Pleasenote, what I provided was an example to show the logic.  You would of course pass in the dataset which you have (and I don't!) using a set statement.

data want;
  set yourdata;
  account_id=substr(account_id,findc(account_id,"123456789"));
run;

Replace the word yourdata with the dataset name.

andyoey
Calcite | Level 5

Thanks, finally it's working

Was not working yesterday since I combined it with another syntax which cause the error

Really appreciate your help

Kurt_Bremser
Super User

Storing an accountID as numeric does not make sense in SAS, as the maximum reliable precision of numeric data in datasets is 15 decimal digits, so you will lose information.

Store IDs in character variables.

 

@RW9's solution will work for all your values, see

data have;
input account_id $20.;
cards;
00134578919018018
00245819124782933
00011238194719972
;
run;

data want;
set have;
account_id=substr(account_id,findc(account_id,"123456789"));
run;

proc print data=want noobs;
run;

Result:

  account_id

134578919018018
245819124782933
11238194719972 
Ksharp
Super User

Here are two another ways.

 

data have;
input account_id $20.;
cards;
00134578919018018
00245819124782933
00011238194719972
;
run;

data want;
set have;
way1=substr(account_id,verify(account_id,"0"));
way2=prxchange('s/^0+//',-1,strip(account_id));
run;

proc print noobs;run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1728 views
  • 3 likes
  • 4 in conversation