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

In the below code:

case when strip(col1) then "DIGIT"

when anyalpha( strip(col1)) then "ALPHA"

else "DIGIT"

I am confused about the first statement. Under what condition will it evaluate to 'DIGIT'? When col1 = null? I understand the second case....if col1 has an alphabet, it will evaluate to "ALPHA"

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

It makes very little sense to me. You don't say whether col1 is character or numeric, but when I try it with a numeric variable it fails with

ERROR: Function STRIP requires a character expression as argument 1.

so we'll assume that col1 is character.

If it's anything other than blank, the first when clause will be satisfied, and the result will be "DIGIT". If it's blank, the second when clause won't be satisfied, and it will fall through to the else clause, and the result will be "DIGIT".

I can't figure out how to get a result of "ALPHA"!

Tom

View solution in original post

2 REPLIES 2
jwillis
Quartz | Level 8

Eagles,

The Strip(function) works on character variables.  If you were to assume that any value that does not have an alpha, is a numeric, then this code should work for you.

case

   when  anyalpha( strip(col1)) then "ALPHA"

   else "DIGIT" end as variable_type

TomKari
Onyx | Level 15

It makes very little sense to me. You don't say whether col1 is character or numeric, but when I try it with a numeric variable it fails with

ERROR: Function STRIP requires a character expression as argument 1.

so we'll assume that col1 is character.

If it's anything other than blank, the first when clause will be satisfied, and the result will be "DIGIT". If it's blank, the second when clause won't be satisfied, and it will fall through to the else clause, and the result will be "DIGIT".

I can't figure out how to get a result of "ALPHA"!

Tom

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2497 views
  • 0 likes
  • 3 in conversation