Hi,
I have an input table with a character column called "CUST_NO". It includes values such as these:
"4512648"
"5487512"
"6123658"
"6548756"
The first character will always be 4, 5, or 6.
What I want to do is to reduce the the first character of each by 3. So the output should be like this:
"1512648"
"2487512"
"3123658"
"3548756"
I figure I might use an expression which starts this way:
firstchar = substr(CUST_NO,1,1)
case
when firstchar = "4" then firstchar = "1"
when firstchar = "5" then firstchar = "2"
when firstchar = "6" then firstchar = "3"
end
However, I can't think of an elegant way to proceed after this. Can you please advise me?
data have;
input CUST_NO $;
firstchar=put(input(substr(CUST_NO,1,1),8.)-3,1.)||strip(substr(CUST_NO,2));
cards;
4512648
5487512
6123658
6548756
;
Thanks,
Jagadish
data have;
input CUST_NO $;
firstchar=put(input(substr(CUST_NO,1,1),8.)-3,1.)||strip(substr(CUST_NO,2));
cards;
4512648
5487512
6123658
6548756
;
Thanks,
Jagadish
Thanks, you're a top-quality Jagadish.
Alternatively you could translate the character digits and use substr on the left side of =.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.