<?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: Use of quotes in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179493#M34302</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming you're trying to get a list of CSV files from a directory, and assuming you're on Windows?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Dec 2013 16:42:06 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2013-12-20T16:42:06Z</dc:date>
    <item>
      <title>Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179490#M34299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am attempting to collect all of the csv files in a folder using the filename and pipe statements. I can get it to work when I directly specify what the dir is, but wondered if I could have it inserted through a macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code that I think should work is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %macro um;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let source = C:\Users\Home\Folder;&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let me = %quote(%'dir %"&amp;amp;source\*.csv%" %');&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rex = %bquote(filename DIRLIST pipe &amp;amp;me.);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename DIRLIST pipe &amp;amp;me.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;rex;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data dirlist ;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile dirlist lrecl=200 truncover;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input line $200.;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if input(substr(line,1,10), ?? mmddyy10.) = . then delete;&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;11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parse = substr(line,40,50 );&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_name = substr(parse,1,length(parse)-4);&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep file_name parse;&lt;/P&gt;&lt;P&gt;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend;&lt;/P&gt;&lt;P&gt;16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %um;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I highlighted in blue where the lines should be inserted inside of quotation marks. For reference line 5 and 6 should duplicate the same text, which would be&lt;/P&gt;&lt;P&gt;filename dirlist pipe 'dir "C:\Users\Home\Folder\*.csv" ';&lt;/P&gt;&lt;P&gt;But when I run it, it always gives me the error "ERROR: Error in the FILENAME statement.". It seems that the main issue here is the use of unbalanced quotation marks in the macro, otherwise I could simply have it written as filename dirlist pipe 'dir "&amp;amp;source.\*.csv" '; But this statement because I have not specified %quote absorbs the parentheses. Any advice on how to have this run correctly would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 15:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179490#M34299</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2013-12-20T15:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179491#M34300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are likely attempting to generate way too many quotes to begin with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename dirlist pipe "dir &amp;amp;source.\*.csv"; should work as the DIR command doesn't require the path to be in quotes. However you may want to check this link for possible other issues: &lt;A href="http://support.sas.com/kb/41/863.html"&gt;http://support.sas.com/kb/41/863.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179491#M34300</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-12-20T16:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179492#M34301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I remove the quotes (' ')from the dir statement I am given this response&lt;/P&gt;&lt;P&gt;ERROR: Error in the FILENAME statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 23-2: Invalid option name dir.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree that the cause of the problem is adding two sets of quotation marks, but wondered if anyone had an idea of how to either do this in more steps so the macro wouldn't crash, or another way to have program read the quotation marks correctly. Of note I can get it to insert the correct line into the macro, but then the filename statement doesn't run correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179492#M34301</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2013-12-20T16:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179493#M34302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming you're trying to get a list of CSV files from a directory, and assuming you're on Windows?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179493#M34302</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-12-20T16:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179494#M34303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Correct on both accounts&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179494#M34303</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2013-12-20T16:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179495#M34304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/1409543/using-sas-macro-to-pipe-a-list-of-filenames-from-a-windows-directory" title="http://stackoverflow.com/questions/1409543/using-sas-macro-to-pipe-a-list-of-filenames-from-a-windows-directory"&gt;Using SAS Macro to pipe a list of filenames from a Windows directory - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a whole bunch of different solutions to the same question. Hopefully one works for you &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One other thing, I'm surprised to not see a scan function in your code to get the file name.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179495#M34304</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-12-20T16:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Use of quotes in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179496#M34305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the advice, the scan function was written farther down in the macro and I cut it off at reading the file names into table so there wouldn't be unnecessary code. But here is what the code looks like once I implemented your suggestions and it is working now.&lt;/P&gt;&lt;P&gt;%LET source = C:\Users\Home\Documents\;&lt;/P&gt;&lt;P&gt;%LET library = out;&lt;/P&gt;&lt;P&gt;libname &amp;amp;library "&amp;amp;source";&lt;/P&gt;&lt;P&gt;%macro daily(type = );&lt;/P&gt;&lt;P&gt;%macro get_filenames(location);&lt;/P&gt;&lt;P&gt;filename _dir_ "%bquote(&amp;amp;location.)";&lt;/P&gt;&lt;P&gt;data filenames(keep=memname);&lt;/P&gt;&lt;P&gt;&amp;nbsp; handle=dopen( '_dir_' );&lt;/P&gt;&lt;P&gt;&amp;nbsp; if handle &amp;gt; 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count=dnum(handle);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname=dread(handle,i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output filenames;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; rc=dclose(handle);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;filename _dir_ clear;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%get_filenames(&amp;amp;source);&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;data dirlist ;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set filenames;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(memname,length(memname)-2,3) ~="&amp;amp;type" then delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; parse = substr(memname,1,length(memname)-4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_name = memname;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep file_name parse;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select parse, file_name&lt;/P&gt;&lt;P&gt;into :parse_list separated by '*', :file_list separated by '*'&lt;/P&gt;&lt;P&gt;from dirlist;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%let cntlist = &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;cntlist;&lt;/P&gt;&lt;P&gt;%let parse = %scan(&amp;amp;parse_list.,&amp;amp;I.,"*");&lt;/P&gt;&lt;P&gt;%let file = %scan(&amp;amp;file_list.,&amp;amp;I.,"*");&lt;/P&gt;&lt;P&gt;proc import out=daily_&amp;amp;i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datafile="&amp;amp;source\&amp;amp;parse"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbms=csv replace;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getnames=yes;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; guessingrows=10000;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%daily(type = txt);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 17:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-quotes-in-macro/m-p/179496#M34305</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2013-12-20T17:35:43Z</dc:date>
    </item>
  </channel>
</rss>

