<?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: macro failure due to hyphen? (directory creation) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481181#M124431</link>
    <description>&lt;P&gt;Any reason not to use the DCREATE() function directly?&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=ja" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=ja&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
rc=dcreate("With-Hyphens", "C:\_localdata\temp\");
put rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Or try the method here: &lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jul 2018 16:55:02 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-25T16:55:02Z</dc:date>
    <item>
      <title>macro failure due to hyphen? (directory creation)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481171#M124428</link>
      <description>&lt;P&gt;I'm using a macro I found online to create Windows directories on my local disk. It's failing if the directory name contains hyphens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can explain&amp;nbsp;what is going on?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the problematic code (&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Is-it-possible-to-use-sas-to-create-a-new-folder-in-my-own-drive/td-p/54911)" target="_blank"&gt;source&lt;/A&gt;)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO makeDirectory(DIR=);
  %LET COUNT=0;
  %LET DLM=\;

  %IF %SUBSTR(&amp;amp;DIR,%LENGTH(&amp;amp;DIR),1) NE &amp;amp;DLM %THEN %DO;
    %LET DIR=&amp;amp;DIR&amp;amp;DLM;
                                                  %END;
  %DO J=1 %TO %LENGTH(&amp;amp;DIR);
    %IF %SUBSTR(&amp;amp;DIR,&amp;amp;J,1)=&amp;amp;DLM %THEN %DO;
      %LET COUNT=%EVAL(&amp;amp;COUNT+1);
                                      %END; 
  %END;

  %LET DRIVE=%SUBSTR(&amp;amp;DIR,1,3);
  %LET LEVEL=&amp;amp;DRIVE;

  %DO I=2 %TO &amp;amp;COUNT;
    %LET WORD=%SCAN(&amp;amp;DIR,&amp;amp;I,&amp;amp;DLM);
    %LET LNEW=&amp;amp;LEVEL&amp;amp;WORD&amp;amp;DLM;
    data _null_;
    rc=filename('newdir',"&amp;amp;lnew");
      c=dopen('newdir');
      if c=0 then new=dcreate("&amp;amp;word","&amp;amp;level");
    run;
    %LET LEVEL=&amp;amp;LNEW;
  %END;
%MEND;	&lt;BR /&gt;&lt;BR /&gt;  /* this will fail */&lt;BR /&gt;%makeDirectory(Dir=C:\TEMP\WITH-HYPHENS); &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the error from the log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SYMBOLGEN:  Macro variable DIR resolves to C:\TEMP\WITH-HYPHEN\
SYMBOLGEN:  Macro variable J resolves to 13
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: %SUBSTR(&amp;amp;DIR,&amp;amp;J,1)=&amp;amp;DLM
SYMBOLGEN:  Macro variable DLM resolves to \
ERROR: The macro MAKEDIRECTORY will stop executing.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 16:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481171#M124428</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-07-25T16:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: macro failure due to hyphen? (directory creation)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481181#M124431</link>
      <description>&lt;P&gt;Any reason not to use the DCREATE() function directly?&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=ja" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=ja&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
rc=dcreate("With-Hyphens", "C:\_localdata\temp\");
put rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Or try the method here: &lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 16:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481181#M124431</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-25T16:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: macro failure due to hyphen? (directory creation)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481193#M124433</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%IF&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%QSUBSTR&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;DIR&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%LENGTH&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;DIR&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;NE&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;DLM &lt;SPAN class="token macrostatement"&gt;%THEN&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%DO&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But yes, I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;,&amp;nbsp;this is a lot of work to write such a macro when you can use a built-in function to do the same thing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 17:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481193#M124433</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-25T17:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: macro failure due to hyphen? (directory creation)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481196#M124434</link>
      <description>&lt;P&gt;Thank you for replying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not using DCREATE() directly because it requires that the parent directory already exists. The macro I found is&amp;nbsp;iteratively creates parent directories as needed. I -think- the error is occurring&amp;nbsp;in the "J loop", so I don't believe there's any problem with the actual creation of each directory (maybe I should have simplified my macro before posting!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did consider OPTIONS DLCREATEDIR&amp;nbsp;however there's the risk that that option is disabled. If not for that consideration, the approach would be ideal.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 17:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481196#M124434</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-07-25T17:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: macro failure due to hyphen? (directory creation)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481197#M124435</link>
      <description>&lt;P&gt;That does the trick, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 17:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-failure-due-to-hyphen-directory-creation/m-p/481197#M124435</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-07-25T17:18:34Z</dc:date>
    </item>
  </channel>
</rss>

