<?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: rename variabile with an element of list by macro variable in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699503#M9495</link>
    <description>&lt;P&gt;You have a number of issues here, and I strongly suggest you start by hard-coding a simple example using just the value&amp;nbsp;&lt;SPAN&gt;04050606 and get your SQL code to work without macro language. If you can't get that to work, then you will never get the macro version to work. So, please show us a simple example of this working properly without macro language. That's the starting point for getting this to work and the starting point for further discussions in this thread.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, the construct&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;as '012345'n&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;does not work in SQL.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2020 14:12:44 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-11-17T14:12:44Z</dc:date>
    <item>
      <title>rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699496#M9493</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I created a macro variable using proc sql ....select into....&lt;/P&gt;&lt;P&gt;The macro variable is for example:&lt;/P&gt;&lt;P&gt;%put &amp;amp;top10.; run;&lt;/P&gt;&lt;P&gt;'04050606', '94958693', '20494585'....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to rename a variable of a dataset with the first element of list macro variable that is a numeric code.&lt;/P&gt;&lt;P&gt;I used this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table prova_new as select&lt;BR /&gt;drg_new, _c2_ as '%scan('&amp;amp;top10.',1,',')'n&lt;BR /&gt;from prova;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it doesn't work:&lt;/P&gt;&lt;PRE class="sasLog"&gt;ERROR 22-322: Expecting a name.&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 13:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699496#M9493</guid>
      <dc:creator>antosferry</dc:creator>
      <dc:date>2020-11-17T13:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699500#M9494</link>
      <description>&lt;P&gt;Your macro variable looks like it has been built to populate a list for the IN operator, so it is not suited to be used as variable names because of the quotes.&lt;/P&gt;
&lt;P&gt;So your first step should be to build that macro variable without the quotes, and blanks as separators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'%scan('&amp;amp;top10.',1,',')'n&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Two issues here: the single quotes prevent macro trigger resolution, so this translates to&lt;/P&gt;
&lt;PRE&gt;'%scan(' &amp;amp;top10. ',1,' , ')' n&lt;/PRE&gt;
&lt;P&gt;(blanks added to show the resulting breaks between separate strings).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have built your list without quotes and commas, change the macro call to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;c2_%scan(&amp;amp;top10.,1, )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the use of the c2_ prefix makes using a name literal unnecessary.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699500#M9494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-17T14:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699503#M9495</link>
      <description>&lt;P&gt;You have a number of issues here, and I strongly suggest you start by hard-coding a simple example using just the value&amp;nbsp;&lt;SPAN&gt;04050606 and get your SQL code to work without macro language. If you can't get that to work, then you will never get the macro version to work. So, please show us a simple example of this working properly without macro language. That's the starting point for getting this to work and the starting point for further discussions in this thread.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, the construct&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;as '012345'n&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;does not work in SQL.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699503#M9495</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-17T14:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699512#M9496</link>
      <description>&lt;P&gt;Excuse me,&lt;/P&gt;&lt;P&gt;i used this coding&lt;/P&gt;&lt;P&gt;data prova_new ;&lt;BR /&gt;set prova;&lt;/P&gt;&lt;P&gt;rename _c2_='%scan("&amp;amp;top10.",1,"',")'n;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to create the variable with the result of scan and it work well. So the result is for example the x=04050606 without quote.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you write all code programming you should use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="text"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699512#M9496</guid>
      <dc:creator>antosferry</dc:creator>
      <dc:date>2020-11-17T14:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699515#M9497</link>
      <description>&lt;P&gt;I have given you a full explanation and code that should work. First change the creation of the macro variable.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699515#M9497</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-17T14:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699521#M9498</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356590"&gt;@antosferry&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Excuse me,&lt;/P&gt;
&lt;P&gt;i used this coding&lt;/P&gt;
&lt;P&gt;data prova_new ;&lt;BR /&gt;set prova;&lt;/P&gt;
&lt;P&gt;rename _c2_='%scan("&amp;amp;top10.",1,"',")'n;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also tried to create the variable with the result of scan and it work well. So the result is for example the x=04050606 without quote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you write all code programming you should use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="text"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As I said, you need to first create code that works without macro language, for one case. Show us code that works without macro language and then we can help you turn it into code that works with macro language. If you can't get it to work without macro language, then it will never work with macro language.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699521#M9498</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-17T14:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699532#M9499</link>
      <description>&lt;P&gt;You can use %PUT statements to test if you can generate the text you need.&lt;/P&gt;
&lt;PRE&gt;645   %let top10='04050606', '94958693', '20494585';
646   %put %scan(%superq(top10),1,%str(,))n;
'04050606'n&lt;/PRE&gt;
&lt;P&gt;Then you can use it to generate code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table prova_new as 
  select drg_new
       , _c2_ as %scan(%superq(top10),1,%str(,))n
  from prova
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Watch out for spaces in your list.&amp;nbsp; If there are spaces before the commas then that simple code will not work as then the N will not be right after the close quote.&lt;/P&gt;
&lt;PRE&gt;647   %let top10='04050606' , '94958693' , '20494585';
648   %put %scan(%superq(top10),1,%str(,))n;
'04050606' n
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 15:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699532#M9499</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-17T15:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: rename variabile with an element of list by macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699802#M9501</link>
      <description>&lt;P&gt;Thank you very much, it works well!!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 14:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/rename-variabile-with-an-element-of-list-by-macro-variable/m-p/699802#M9501</guid>
      <dc:creator>antosferry</dc:creator>
      <dc:date>2020-11-18T14:23:25Z</dc:date>
    </item>
  </channel>
</rss>

