BookmarkSubscribeRSS Feed
ranjita
Calcite | Level 5

I have a variable called "X", it has alphabets, numbers, special characters etc. I need to search for Upper and Lower Case alphabets from a to z and create a flag based on that. Whenever X has a character in it, a variable called flag should have value 1. Writing a if then statement is not an option cause its very long. I need to specify a variable with range of character values from A to Z and the variable flag should be based on that. Please help. Need a solution urgently.

2 REPLIES 2
art297
Opal | Level 21

I would think that you could write an if statement that includes some of the SAS ANY functions, e.g.: anyalpha, anyalnum, anycntrl, anydigit, anylower, anypunct and anyupper.

Tom
Super User Tom
Super User

Some examples would clarify the question, but it sounds like you want the INDEXC() function.

flag = indexc(upcase(x),'ABC');

Then FLAG will have the position where A,B or C first appear in X.  You could treat FLAG as a true/false variable if you want.

Or you could convert it to a 0/1 variable by using:

flag = 0 ^= indexc(upcase(x),'ABC');

or

flag = not not indexc(upcase(x),'ABC');

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1147 views
  • 3 likes
  • 3 in conversation