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.
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.
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 ...
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.
See the character functions in this table:
Some that you may want to look for:
SUBSTR()
FIND()/INDEX()
ANYALPHA()
ANYNUM()
LENGTH()
REVERSE()
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!
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.
Ready to level-up your skills? Choose your own adventure.