BookmarkSubscribeRSS Feed
Sandra94
Calcite | Level 5

How to change "001234" to "1234" in all rows of a column?

 

In one of my columns in the dataset I have customerIDs with "00" added before. I want to delete it at all rows.

Is this possible?

 

Kind regards,

Sandra

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
   CustomerID = "001234";
run;

data want;
   set have;
   id = substr(CustomerID, verify(CustomerID,'0'));
run;
Phil_NZ
Barite | Level 11
data want;
   set have;
       y=substr(x,1,2)
       If y="00" then x1=substr(x,3,4);
else x1=x; run;

@Sandra94 wrote:

In one of my columns in the dataset I have customerIDs with "00" added before. I want to delete it at all rows.

Is this possible?

 

Kind regards,

Sandra


data want;
  set have;
     if substr(customerIDs,1,2) ="00" then delete;
run;
Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
Shmuel
Garnet | Level 18

I understand that the variable CustomerID is char type and its length is 6.

Alternative ways to those already posted:

 

1) customeID = put(input(customeID ,6.),6.);

2) Change the type of the variable to numeric:

data want;
 set have(rename=(customeID =CID));
       customeID = input(CID,6.);
       format customeID 6.;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 983 views
  • 4 likes
  • 4 in conversation