We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

webonomic on 10/02/08


Tagged

sql match regular Expression proc


Versions (?)


Use Regular Expressions in Proc SQL


Published in: SAS 


URL: http://jaredprins.squarespace.com/blog/2008/10/7/some-sas-code-snippets.html

You can use regular expressions within SQL. This can be quite powerful in selecting data that matches certain conditions. The following example shows a simple regular expression which selects only quarterly periods from a table containing years, quarters & months.

  1. data test ;
  2.  
  3. length period $ 7 ;
  4.  
  5. input period ;
  6.  
  7. cards ;
  8.  
  9. 2005
  10.  
  11. 2005Q1
  12.  
  13. 2005JAN
  14.  
  15. ;;
  16.  
  17. run ;
  18.  
  19. proc sql;
  20.  
  21. create table qtrs as
  22.  
  23. select *
  24.  
  25. from test
  26.  
  27. where prxmatch("/\d\d\d\d[qQ][1-4]/",period) ;
  28.  
  29. quit;
  30.  
  31. proc print data=qtrs ;
  32.  
  33. run ;

Report this snippet 

You need to login to post a comment.