<?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: Generate file name conditionally in Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177203#M33911</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To concatenate macro variable values you just need to reference the macro.&amp;nbsp; There is no need for a function like || or CAT() as you would have to do in regular SAS code or other programming languages.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;dsout= %then %do i=1 %to 999;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let dsout = ABC_%sysfunc(put(&amp;amp;i, z3.)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %sysfunc(exist(&amp;amp;dsout)) %then %goto leave;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%leave:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Aug 2014 18:10:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2014-08-27T18:10:08Z</dc:date>
    <item>
      <title>Generate file name conditionally in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177202#M33910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been struggling for a long time to handle string in Macro.&amp;nbsp; I want to generate a data set name according the system file.&amp;nbsp; Simply, I want to generate a file named ABCXXX.&amp;nbsp; XXX is from ABC001 to ABC999.&amp;nbsp; If the name exists, generate the next one with number adding 1.&amp;nbsp; here is what I tried to do: (I want &amp;amp;DsOut is a file name that is not existing in system.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%IF &amp;amp;DsOut= %THEN %DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %DO I=1 %TO 999; &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; %LET DsOut = %SYSFUNC(CATS("ABC_", %SYSFUNC(PUT(&amp;amp;I, Z3.))));&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; %IF %SYSFUNC(exist(&amp;amp;DsOut)) NE 0 %THEN %DO; &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; %GOTO LEAVE;&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; %END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LEAVE:&lt;/P&gt;&lt;P&gt;&amp;nbsp; %END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apparently this does not work at all.&amp;nbsp; Does anyone have any suggestions or you have some example code?&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;Abdu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 17:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177202#M33910</guid>
      <dc:creator>Abdu</dc:creator>
      <dc:date>2014-08-27T17:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Generate file name conditionally in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177203#M33911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To concatenate macro variable values you just need to reference the macro.&amp;nbsp; There is no need for a function like || or CAT() as you would have to do in regular SAS code or other programming languages.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;dsout= %then %do i=1 %to 999;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let dsout = ABC_%sysfunc(put(&amp;amp;i, z3.)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %sysfunc(exist(&amp;amp;dsout)) %then %goto leave;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%leave:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 18:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177203#M33911</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-08-27T18:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Generate file name conditionally in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177204#M33912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your response.&amp;nbsp; I tried the code.&amp;nbsp; It renerate error message:&lt;/P&gt;&lt;P&gt;ERROR: The PUT function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found.&lt;/P&gt;&lt;P&gt;I am using SAS 9.2.&amp;nbsp; Is there something I missed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Abdu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 18:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177204#M33912</guid>
      <dc:creator>Abdu</dc:creator>
      <dc:date>2014-08-27T18:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Generate file name conditionally in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177205#M33913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You must use PUTN() with %SYSFUNC().&amp;nbsp; Note to apply a character format use PUTC().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 18:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177205#M33913</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-08-27T18:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Generate file name conditionally in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177206#M33914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much, Tom.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering that is there any good reference that I can read for this kind of information?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Abdu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 18:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-file-name-conditionally-in-Macro/m-p/177206#M33914</guid>
      <dc:creator>Abdu</dc:creator>
      <dc:date>2014-08-27T18:44:42Z</dc:date>
    </item>
  </channel>
</rss>

