BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ravindrrapaal
Obsidian | Level 7

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'

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Not sure about CI, but here's a way in base SAS:

 

digit5 = input(substr(put(varname, 20.-L), 5), 1.);

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.

ravindrrapaal
Obsidian | Level 7
Hi Yes, I have custonerid of 10 digit, then using RANUNI function in SAS CI campaigns, once the number is genatrated and this is working with that i need to take nth digit. Please advice
JamesAnderson
SAS Employee

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

 

Astounding
PROC Star

Not sure about CI, but here's a way in base SAS:

 

digit5 = input(substr(put(varname, 20.-L), 5), 1.);
ravindrrapaal
Obsidian | Level 7
Thank you so much. It worked.

Review SAS CI360 now.png

 

Want to review SAS CI360? G2 is offering a gift card or charitable donation for each accepted review. Use this link to opt out of receiving anything of value for your review.

 

 

 

 

SAS Customer Intelligence 360

Get started with CI 360

Review CI 360 Release Notes

Open a Technical Support case

Suggest software enhancements

Listen to the Reimagine Marketing podcast

Assess your marketing efforts with a free tool

 

Training Resources

SAS Customer Intelligence Learning Subscription (login required)

Access free tutorials

Refer to documentation

Latest hot fixes

Compatibility notice re: SAS 9.4M8 (TS1M8) or later

 

 

How to improve email deliverability

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.

Review SAS CI360 now.png

 

Want to review SAS CI360? G2 is offering a gift card or charitable donation for each accepted review. Use this link to opt out of receiving anything of value for your review.

 

 

 

 

SAS Customer Intelligence 360

Get started with CI 360

Review CI 360 Release Notes

Open a Technical Support case

Suggest software enhancements

Listen to the Reimagine Marketing podcast

Assess your marketing efforts with a free tool

 

Training Resources

SAS Customer Intelligence Learning Subscription (login required)

Access free tutorials

Refer to documentation

Latest hot fixes

Compatibility notice re: SAS 9.4M8 (TS1M8) or later

 

 

Discussion stats
  • 5 replies
  • 1579 views
  • 0 likes
  • 3 in conversation