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
Try this
data have;
CustomerID = "001234";
run;
data want;
set have;
id = substr(CustomerID, verify(CustomerID,'0'));
run;
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.