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

 

 

The high level view of my program is that i have to query a database and i need to determine if observations in a particular variable are formatted correctly.  Here is my filtering criteria:

 

if position 4 is not "_"

if any position includes "."

if position 4-8 not numeric

if last 4 chars not match variable q

 

then put this observation in a new variable called Q 

 

It seems to me that these are all possible, but part of my problem is that i don't know how to look up in the documentation on how to go about this.  I'm not necessarily looking for someone to give me the answer here, but offer how I can go about finding out how to do this on my own...perhaps give me one example and let me go off on my own. 

 

Any help here is greatly appreciated.  

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Functions can handle all the data inspection.  Some examples:

 

if substr(var, 4, 1) ne '_' then ....;

if index(var, '.') > 0 then ....;

if input(substr(var, 4, 5), ??5.) = . then .....;

if substr(var, length(var)-3) ne q then ....;

 

Putting the observation into a new variable is open to debate, however.  It's not really clear what that means.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

if position 4 is not "_"

 

= if char(thedata,4)="_" then ....

 

if any position includes "."

 

= if index(thedata,".") > 0 then ...

 

if position 4-8 not numeric

 

= if lengthn(compress(substr(thedata,4,4)," ","d")) > 0 then ...

 

if last 4 chars not match variable q

 

= if substr(thedata,lengthn(thedata)-4,4) ne "qqqq" then ...

Astounding
PROC Star

Functions can handle all the data inspection.  Some examples:

 

if substr(var, 4, 1) ne '_' then ....;

if index(var, '.') > 0 then ....;

if input(substr(var, 4, 5), ??5.) = . then .....;

if substr(var, length(var)-3) ne q then ....;

 

Putting the observation into a new variable is open to debate, however.  It's not really clear what that means.

Reeza
Super User

See the character functions in this table:

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&...

 

Some that you may want to look for:

 

SUBSTR()

FIND()/INDEX()

ANYALPHA()

ANYNUM()

LENGTH()

REVERSE()

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 898 views
  • 3 likes
  • 4 in conversation