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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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
  • 1219 views
  • 4 likes
  • 4 in conversation