From: Anders M�rup Jensen on 23 Mar 2010 05:44 I am trying to make a system where it would be convenient to convert a Windows\DOS filename expression with wild cards to an equivalent Perl regular expression. Examples of DOS filenames: *.* ?er*.sas r?p.*s e??d*.r* ??.? Does anybody happen to have, or know how to create, a SAS function (or a SAS macro) that can do the conversion ? Anders M�rup
From: Patrick on 23 Mar 2010 07:57 If you're using SAS9.2 then look up PROC FCPM - else a function style macro could do. Not sure what you exactly want to do - but I assume you would mainly need some logic in this function to convert "wild card" characters to appropriate RegEx "characters".
From: Anders M�rup Jensen on 25 Mar 2010 03:40 "Anders M�rup Jensen" <amo(a)ssi.dk> skrev i en meddelelse news:newscache$r2bqzk$90a$1(a)news.webpartner.dk... >I am trying to make a system where it would be convenient to convert a >Windows\DOS filename expression with wild cards to an equivalent Perl >regular expression. > > Examples of DOS filenames: > > *.* > ?er*.sas > r?p.*s > e??d*.r* > ??.? > > Does anybody happen to have, or know how to create, a SAS function (or a > SAS macro) that can do the conversion ? > > Anders M�rup > comp.soft-sys.sas and www.listserv.uga.edu do not synchronize well, and have not done so for approx. 14 days. I estimate that only one third of the mails to the list hits comp.soft-sys.sas at the moment. I therefore resubmit the answer from Chang Chung on www.listserv.uga.edu to my question : Chang Chung chang_y_chung(a)HOTMAIL.COM wrote: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Hi, Anders,This is an interesting question. If you really want to do >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>this well, then it would be *very* difficult. This is because neither >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>windows file system filenames or the perl reg ex are simple. See the >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>gory details yourself at:on >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>filenames:http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspxon >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>perl reg ex:http://perldoc.perl.org/perlre.htmlIn practice, we can >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>assume away many complications and this will give us a simpler problem that can be easily solved. Let's assume that your input filenames have only letters, numbers, a dot(.), and the two wild characters(*,?), then it is possible to do something like below. Converting the data step into a proper function using proc fcmp is left as an exercise for the interested. :-) Cheers, Chang /* assuming that filenames include only letters, numbers, and a dot(.) as well as the two wild characters. */ data dos; input dos: $200.; cards; *.* ?er*.sas r?p.*s e??d*.r* ??.? ; run; data prx; set dos; length perl $400. d $8.; len = length(dos); do i = 1 to len; c = substr(dos, i, 1); select; when (prxmatch("/[a-zA-Z0-9]/",c)) d = c; when (c=".") d = "\."; when (c="*") d = ".*"; when (c="?") d = "."; otherwise do; putlog "stopped due to an unexpected character, " c; stop; end; end; perl = catt(perl, d); end; keep dos perl; run; /* check */ proc print data=prx; run; /* on lst Obs dos perl 1 *.* .*\..* 2 ?er*.sas .er.*\.sas 3 r?p.*s r.p\..*s 4 e??d*.r* e..d.*\.r.* 5 ??.? ..\.. */ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Hi Chang,Thank you for your help.I agree that the perfect solution to the conversion problem has to be complicated.I would of course have preferred the "perfect" solution, but your solution seems to be sufficient for my purpose, if I add a few national characters.Making a SAS function from your data step solution is a trival task.Best wishes,Anders
|
Pages: 1 Prev: HELP: Somers' D Next: v-fold cross validation in Clustering |