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()

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1586 views
  • 3 likes
  • 4 in conversation