How can i find the nth digit in a 20 digit random number.
Example 1753150515609025 is random number where i want find 5th digit then wanted to use for CASE statment.
CASE
WHEN 5th digit of the 1753150515609025 is <2 THEN 'A'
WHEN 5th digit of the 1753150515609025 is ❤️ THEN 'B'
WHEN 5th digit of the 1753150515609025 is <10 THEN 'C
END'
Not sure about CI, but here's a way in base SAS:
digit5 = input(substr(put(varname, 20.-L), 5), 1.);
Do you actually have a SAS data set to work with?
SAS cannot accurately store integers that long. Is your random number a character string instead of numeric? What's the name of that variable?
Are you working in a DATA step or in SQL? The syntax for CASE WHEN does not appear to be correct syntax for a SAS program, but the right syntax probably depends on all of these questions being answered.
Hi,
Does your random number really need to be that long ?
SAS will handle an integer up to 16 digits (doc).
If you can work with that, the the following approach will find your nth digit and has the added benefit of generating Pass Thru SQL from PROC SQL (which is what CI Studio will do) for most RDBMS:
MOD({your integer variable}, 10) – this returns the last digit
MOD(FLOOR({your integer variable}/10),10) – this returns the 2nd last digit
MOD(FLOOR({your integer variable}/100),10) – this returns the 3rd last digit
MOD(FLOOR({your integer variable}/1000),10) – this returns the 4th last digit
keep adding a zero to the divisor to get the next "digit".
Regards
James
Not sure about CI, but here's a way in base SAS:
digit5 = input(substr(put(varname, 20.-L), 5), 1.);
Want to review SAS Customer Intelligence 360? Gartner and G2 are offering a gift card or charitable donation for each accepted review. Use this link for G2 to opt out of receiving anything of value for your review.
SAS Customer Intelligence 360
Training Resources
SAS Customer Intelligence Learning Subscription (login required)
SAS' Peter Ansbacher shows you how to use the dashboard in SAS Customer Intelligence 360 for better results.
Find more tutorials on the SAS Users YouTube channel.
Want to review SAS Customer Intelligence 360? Gartner and G2 are offering a gift card or charitable donation for each accepted review. Use this link for G2 to opt out of receiving anything of value for your review.
SAS Customer Intelligence 360
Training Resources
SAS Customer Intelligence Learning Subscription (login required)