View previous topic :: View next topic
|
Author |
Message |
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
Hi,
Could you please let me know if there is an option or statement in SAS to check conditions similar to LIKE operator in where statement.
Example:
Code: |
data A;
set B;
where dsn like '%abcd';
or
where dsn like "__abcd';
|
Is there a similar statement that can be used in a IF condition for checking condition as shown below,
Code: |
IF DSN = '%abcd' then account = 'good';
IF DSN = "__abcd' then account = 'good'; |
I am not sure if PROC format can be used for this. Can it be used?
Thanks & Regards, |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
What about the INDEX function, would that help. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Only if you can substitute ranges for your LIKE values.
PROC FORMAT;
VALUE DSNFMT
'rangea'-'rangeb' = 'good'
'rangec'-'ranged' = 'good'; |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
Hi,
Thanks for the reply,
The condition checks require checking of dataset names with strings at specific position, so index was not adequate.
Example, there are 3000 checks like,
$AB.ABC_.CA7%
$AB.____.SMFABC_.%._C
Regards, |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
So what are you trying to achieve and maybe we can help in a more roundabout fashion
Lots of detail please. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
Its quite complex and I am not sure if I can share the in depth details due to security and other formalities.
We are using a CA product that is based on SAS to classify datasets to specific groups.
The product accepts only SAS code "IF conditions" or other statements that can be used inside a data step as PARM or SYSIN for classification.
so I believe there is no alternate way other than SAS IF statements or SAS statements that are used inside a DATA step .
Thanks, |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
You might try a quick test to see if the PRXPARSE function is available in your version of SAS. If so, you have access to Perl regular expressions and much becomes possible. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Have you had a look at PROC SQL which supports the LIKE parameter.
Sorry, should have suggested that earlier, but as my client pays the bill his workload gets priority |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Robert Sample wrote: |
You might try a quick test to see if the PRXPARSE function is available in your version of SAS. If so, you have access to Perl regular expressions and much becomes possible. |
I think you need PRXMATCH too. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
Hi,
Thanks everyone for sharing your knowledge.
As suggested above, PRXMATCH did the trick
equivalent statement of
Code: |
IF DSN = '$AB.ABC_.CA7%' then flag = 'GOOD'; |
is
Code: |
IF prxmatch("/\$AB.ABC[\D.|\d.]{1}.\CA7[\D.|\d.]{0,20}/",DSN) then flag = 'GOOD'; |
I have not heard of PERL earlier and thought they were shiny thingies under the sea, but this PERL is interesting to learn
Thanks, |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Good catch, Peter!
Glad to hear your problem is resolved, Vasanth. Perl is worth knowing -- even though it's probably the most dangerous programming language I've run across so far. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Quote: |
even though it's probably the most dangerous programming language I've run across so far.
|
Finding dirty words? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Perl variables are:
1. allowed to be very long
2. case-sensitive ($ABC and $abc are two different variables)
3. defined upon first reference so typos cause extra variables
4. the first character determines whether it is string, array, or hash
5. scope depends upon how the variable is defined and used
So there is much potential for mayhem, chaos, and extraneous side-effects! |
|
Back to top |
|
|
|