<?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 a macro in a file name after a set command in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452938#M5162</link>
    <description>&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Saskatoon-User-Group/Gopinath-SASArrays-2014.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Saskatoon-User-Group/Gopinath-SASArrays-2014.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if the above link is helpful&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Apr 2018 19:45:46 GMT</pubDate>
    <dc:creator>radoyle</dc:creator>
    <dc:date>2018-04-10T19:45:46Z</dc:date>
    <item>
      <title>Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452927#M5161</link>
      <description>&lt;P&gt;I am trying to loop a command over a list of nonsequential values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The command would ideally open two files, indexed by the values, so e.g first_22 and second_22; first_28 and second_28, etc.&lt;/P&gt;&lt;P&gt;and then, after some data manipulations, save the resulting file as FinalFile22, Finalfile29.&lt;/P&gt;&lt;P&gt;Unfortunately the following line produces an error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set mylib."first_&amp;amp;value";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried various places to put the dots and the quotation marks, all of which eventually produce an error of some sort.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sketch of the code is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any help with this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro aaa(values); 
&lt;BR /&gt;
%let count=%sysfunc(countw(&amp;amp;values));
&lt;BR /&gt;
%do i = 1 %to &amp;amp;count; 
&lt;BR /&gt;%let value=%qscan(&amp;amp;values,&amp;amp;i,%str(,));

&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;libname mylib '/project/this/data';

&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data FirstData;&lt;BR /&gt;&lt;BR /&gt;
set mylib."first_&amp;amp;value";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
[...]
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
data SecondData;&lt;BR /&gt;&lt;BR /&gt;
set mylib."second_&amp;amp;value";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
[...]
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
data project.FinalFile&amp;amp;value;&lt;BR /&gt;&lt;BR /&gt;
set Finalfile;run;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;
%end; &lt;BR /&gt; &lt;BR /&gt;
%mend; &lt;BR /&gt;&lt;BR /&gt;
%mtaq(%str(22,28,34)); &lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 19:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452927#M5161</guid>
      <dc:creator>sasuser33</dc:creator>
      <dc:date>2018-04-10T19:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452938#M5162</link>
      <description>&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Saskatoon-User-Group/Gopinath-SASArrays-2014.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Saskatoon-User-Group/Gopinath-SASArrays-2014.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if the above link is helpful&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 19:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452938#M5162</guid>
      <dc:creator>radoyle</dc:creator>
      <dc:date>2018-04-10T19:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452940#M5163</link>
      <description>&lt;P&gt;Remove the quotes. Remember it needs to become valid SAS code, and the quotes are not valid..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set mylib.first_&amp;amp;value;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 19:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452940#M5163</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-10T19:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452944#M5165</link>
      <description>&lt;P&gt;Thank you, Reeza&lt;BR /&gt;&lt;BR /&gt;If I do not put anything in quotes, I get the following error message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;ERROR: File mylib.first.DATA does not exist.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;NOTE: Line generated by the macro variable "VALUE".&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;849 mylist.first22&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;________&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;22&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;________&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;200&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY, &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 20:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452944#M5165</guid>
      <dc:creator>sasuser33</dc:creator>
      <dc:date>2018-04-10T20:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452948#M5166</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s suggestion does work when i tested your code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;BR /&gt;94 %macro aaa(values);&lt;BR /&gt;95&lt;BR /&gt;96 %let count=%sysfunc(countw(&amp;amp;values));&lt;BR /&gt;97&lt;BR /&gt;98 %do i = 1 %to &amp;amp;count;&lt;BR /&gt;99 %let value=%qscan(&amp;amp;values,&amp;amp;i,%str(,));&lt;BR /&gt;100&lt;BR /&gt;&lt;STRONG&gt;101 /*libname mylib '/project/this/data';*/&lt;/STRONG&gt;&lt;BR /&gt;102&lt;BR /&gt;103 %put data FirstData;&lt;BR /&gt;104 %put set mylib.first_&amp;amp;value;&lt;BR /&gt;105&lt;BR /&gt;106&lt;BR /&gt;1&lt;STRONG&gt;07 /*data SecondData;*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;108 /*set mylib."second_&amp;amp;value";*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;109 /*[...]*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;110 /**/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;111 /*data project.FinalFile&amp;amp;value;*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;112 /*set Finalfile;run; */&lt;/STRONG&gt;&lt;BR /&gt;113 %end;&lt;BR /&gt;114 %mend;&lt;BR /&gt;115 %aaa(%str(22,28,34))&lt;BR /&gt;data FirstData&lt;BR /&gt;set mylib.first_22&lt;BR /&gt;data FirstData&lt;BR /&gt;set mylib.first_28&lt;BR /&gt;data FirstData&lt;BR /&gt;set mylib.first_34&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 20:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452948#M5166</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-10T20:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452949#M5167</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;So I guess the question is why I get an error message, then &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 20:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452949#M5167</guid>
      <dc:creator>sasuser33</dc:creator>
      <dc:date>2018-04-10T20:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452950#M5168</link>
      <description>&lt;P&gt;what is this&amp;nbsp;&lt;STRONG&gt;mylist&lt;/STRONG&gt;&lt;EM&gt;.first22 &lt;/EM&gt;libname&lt;EM&gt;?&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;and is&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%mtaq&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;a different maco definition other than aaa?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 20:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452950#M5168</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-10T20:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452951#M5169</link>
      <description>&lt;P&gt;Yes, sorry about that&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&lt;SPAN&gt;what is this&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;mylist&lt;/STRONG&gt;&lt;EM&gt;.first22&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN&gt;libname&lt;/SPAN&gt;&lt;EM&gt;?&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;It should be&amp;nbsp;&lt;STRONG&gt;mylib&lt;/STRONG&gt;.first22&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) No, the macro should be called&amp;nbsp;&lt;/P&gt;&lt;P&gt;%aaa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, since I'm not an expert programmer at all, I have been relying on some examples, hence the issues with copy-pasting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, I appreciate your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 20:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452951#M5169</guid>
      <dc:creator>sasuser33</dc:creator>
      <dc:date>2018-04-10T20:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452956#M5170</link>
      <description>&lt;P&gt;Don't add the macro quoting. It is confusing the parser into seeing an extra token.&lt;/P&gt;
&lt;P&gt;If you are going to use the value as part of a dataset name then it cannot contain any characters that need to be macro quoted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let value=%scan(&amp;amp;values,&amp;amp;i,%str(,));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to keep the macro quoting (why?) then you can use %unquote() to remove it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set %unquote(mylib.first_&amp;amp;value);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use a name literal so that SAS knows it is one token.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set mylib."first_&amp;amp;value"n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452956#M5170</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-10T21:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452966#M5171</link>
      <description>&lt;P&gt;Before you make your code a macro make sure your base case works.&lt;/P&gt;
&lt;P&gt;Then add your macro variable parameters one at a time and test each one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you don't run into these issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452966#M5171</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-10T21:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452978#M5172</link>
      <description>&lt;P&gt;Thanks a lot, Tom&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your suggestions fix this problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the meantime, for some reason the code does not loop through the list as I was hoping it would, and just does everything (correctly) for the first element of the list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that's a separate problem and I'll try to see if I can solve it on my own &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 22:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452978#M5172</guid>
      <dc:creator>sasuser33</dc:creator>
      <dc:date>2018-04-10T22:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a file name after a set command</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452979#M5173</link>
      <description>You are right, Reeza.&lt;BR /&gt;That was my approach but apparently the quoting messed things up.&lt;BR /&gt;Thank you for your advice.</description>
      <pubDate>Tue, 10 Apr 2018 22:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-a-macro-in-a-file-name-after-a-set-command/m-p/452979#M5173</guid>
      <dc:creator>sasuser33</dc:creator>
      <dc:date>2018-04-10T22:07:14Z</dc:date>
    </item>
  </channel>
</rss>

