<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: using %scan (maybe) to extract date from macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212829#M39314</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;string juggling, just like spinning plates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let myStr&lt;/P&gt;&lt;P&gt;=fileNameXy_blah_blah07282015.csv;&lt;/P&gt;&lt;P&gt;*1234567890123456789012345678901234567890;&lt;/P&gt;&lt;P&gt;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^------^;&lt;/P&gt;&lt;P&gt;%let length_date = %length(mmddccyy);&lt;/P&gt;&lt;P&gt;%put &amp;amp;=length_date;&lt;/P&gt;&lt;P&gt;%let position_dot =%index(&amp;amp;mystr,.);&lt;/P&gt;&lt;P&gt;%put &amp;amp;=position_dot;&lt;/P&gt;&lt;P&gt;%let number =&lt;/P&gt;&lt;P&gt;%substr(&amp;amp;mystr,%eval(&amp;amp;position_dot - &amp;amp;length_date),&amp;amp;length_date);&lt;/P&gt;&lt;P&gt;*eval not necessary in previous line;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=number;&lt;/P&gt;&lt;P&gt;%let date = %sysfunc(mdy&lt;/P&gt;&lt;P&gt;(%substr(&amp;amp;number,1,2)&lt;/P&gt;&lt;P&gt;,%substr(&amp;amp;number,3,2)&lt;/P&gt;&lt;P&gt;,%substr(&amp;amp;number,5,4)&lt;/P&gt;&lt;P&gt;));&lt;/P&gt;&lt;P&gt;%put &amp;amp;=date;*is.a SAS date;&lt;/P&gt;&lt;P&gt;%put %sysfunc(putn(&amp;amp;date&amp;nbsp; ,weekdate29.));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see also the page and paper Macro Loops with Dates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates" title="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates"&gt;http://www.sascommunity.org/wiki/Macro_Loops_with_Dates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Jul 2015 23:35:26 GMT</pubDate>
    <dc:creator>Ron_MacroMaven</dc:creator>
    <dc:date>2015-07-28T23:35:26Z</dc:date>
    <item>
      <title>using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212820#M39305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I plan to use file names as macro arguments. The file names start with different numbers of characters and end with mmddyyyy.csv . To extract the mm (month), dd (day of month), and yyyy (year), I would like to use the %scan function (as opposed to the more complicated code needed to run prx functions in macros). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if&lt;/P&gt;&lt;P&gt;%let myStr&amp;nbsp; = fileNameXy_blah_blah07282015.csv,&lt;/P&gt;&lt;P&gt;can someone please tell me if I can use %scan to get 07282015 from &amp;amp;myStr?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, Bruce&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 18:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212820#M39305</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2015-07-28T18:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212821#M39306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps substr() with length() is an alternative? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 18:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212821#M39306</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-07-28T18:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212822#M39307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so I would use %length to determine how many characters &amp;amp;myStr has and then figure out how far from the end I'd need to start as my first position in %substr. I'll give it a try. Thanks for the suggestion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bruce&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 18:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212822#M39307</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2015-07-28T18:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212823#M39308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Explore using macro language %SYSFUNC(...) along with SCAN (the function), along with modifier / string arguments to extract the numeric data desired.&amp;nbsp; The DOC is pretty self-explanatory as far as the various coding techniques and results / behavior desired.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;BR /&gt;SBBWorks, Inc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 19:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212823#M39308</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-07-28T19:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212824#M39309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let myStr&amp;nbsp; = fileNameXy_blah_blah07282015.csv;&lt;/P&gt;&lt;P&gt;%let num=%sysfunc(compress(&amp;amp;mystr,,kd));&lt;/P&gt;&lt;P&gt;%put &amp;amp;num;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 19:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212824#M39309</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2015-07-28T19:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212825#M39310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Will it always be CSV?&lt;/P&gt;&lt;P&gt;Keep in mind the reverse() function. A double reverse and substr would work if you always know that you'll have that structure.&lt;/P&gt;&lt;P&gt;untested:&lt;/P&gt;&lt;P&gt;reverse(substr(reverse(string), 4, 8));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 19:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212825#M39310</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-07-28T19:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212826#M39311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With your exact example this works&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;%let date= &lt;/SPAN&gt;&lt;SPAN style="color: #ff0080; font-size: 10pt; font-family: SAS Monospace;"&gt;%scan&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;(&amp;amp;mystr,1,,AP);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;%put &amp;amp;date;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 19:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212826#M39311</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-28T19:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212827#M39312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Good idea, but I don't think %reverse is a macro function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;thanks, Bruce&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 20:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212827#M39312</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2015-07-28T20:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212828#M39313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks very much. I wish I could check more than one "correct answer". Yours works fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again, Bruce&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 20:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212828#M39313</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2015-07-28T20:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: using %scan (maybe) to extract date from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212829#M39314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;string juggling, just like spinning plates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let myStr&lt;/P&gt;&lt;P&gt;=fileNameXy_blah_blah07282015.csv;&lt;/P&gt;&lt;P&gt;*1234567890123456789012345678901234567890;&lt;/P&gt;&lt;P&gt;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^------^;&lt;/P&gt;&lt;P&gt;%let length_date = %length(mmddccyy);&lt;/P&gt;&lt;P&gt;%put &amp;amp;=length_date;&lt;/P&gt;&lt;P&gt;%let position_dot =%index(&amp;amp;mystr,.);&lt;/P&gt;&lt;P&gt;%put &amp;amp;=position_dot;&lt;/P&gt;&lt;P&gt;%let number =&lt;/P&gt;&lt;P&gt;%substr(&amp;amp;mystr,%eval(&amp;amp;position_dot - &amp;amp;length_date),&amp;amp;length_date);&lt;/P&gt;&lt;P&gt;*eval not necessary in previous line;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=number;&lt;/P&gt;&lt;P&gt;%let date = %sysfunc(mdy&lt;/P&gt;&lt;P&gt;(%substr(&amp;amp;number,1,2)&lt;/P&gt;&lt;P&gt;,%substr(&amp;amp;number,3,2)&lt;/P&gt;&lt;P&gt;,%substr(&amp;amp;number,5,4)&lt;/P&gt;&lt;P&gt;));&lt;/P&gt;&lt;P&gt;%put &amp;amp;=date;*is.a SAS date;&lt;/P&gt;&lt;P&gt;%put %sysfunc(putn(&amp;amp;date&amp;nbsp; ,weekdate29.));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see also the page and paper Macro Loops with Dates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates" title="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates"&gt;http://www.sascommunity.org/wiki/Macro_Loops_with_Dates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jul 2015 23:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-scan-maybe-to-extract-date-from-macro-variable/m-p/212829#M39314</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-07-28T23:35:26Z</dc:date>
    </item>
  </channel>
</rss>

