<?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: Select from the first to the k-th element in a macro list variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524846#M4846</link>
    <description>&lt;P&gt;Thank you very much for your answer!&lt;/P&gt;</description>
    <pubDate>Sat, 05 Jan 2019 21:30:24 GMT</pubDate>
    <dc:creator>AndreMenezes</dc:creator>
    <dc:date>2019-01-05T21:30:24Z</dc:date>
    <item>
      <title>Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524416#M4781</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose that I have the following macro list variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list = a1, a2, a3, a4, a5;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I want to create another macro variable selecting the elements a1, a2 and a3 how can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AFM.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 00:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524416#M4781</guid>
      <dc:creator>AndreMenezes</dc:creator>
      <dc:date>2019-01-04T00:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524420#M4784</link>
      <description>&lt;P&gt;You really turned this into a difficult problem by inserting commas into your list.&amp;nbsp; Is there any chance you can go back and change the code so that you get:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;%let list = a1 a2 a3 a4 a5;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 01:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524420#M4784</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-04T01:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524422#M4786</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;it's easier without the commas - then check out the %scan macro function which allows you to select the nth element from the list, put that inside a %do loop and you're done....&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 01:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524422#M4786</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2019-01-04T01:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524427#M4787</link>
      <description>&lt;P&gt;If you need to keep the commas, here's a trick that might work.&amp;nbsp; (I can't test it at the moment so that part is up to you).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let list = a1, a2, a3, a4, a5;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%macro first3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%global newmacrovar;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%let newmacrovar=;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%local k;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%do k=1 %to 3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let newmacrovar = &amp;amp;newmacrovar %scan("&amp;amp;list", &amp;amp;k, ", ");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%mend first3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm omitting the commas from the new macro variable, but they can be added with a single additional line of code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%do k=1 %to 3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let newmacrovar = &amp;amp;newmacrovar %scan("&amp;amp;list", &amp;amp;k, ", ");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF0000"&gt;%if &amp;amp;k &amp;lt; 3 %then %let newmacrovar = &amp;amp;newmacrovar,;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 02:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524427#M4787</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-04T02:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524796#M4833</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list = a1, a2, a3, a4, a5;
%let want=%sysfunc(prxchange(s/\W+\w+\W+\w+$//,1,%nrbquote(&amp;amp;list)));

%put &amp;amp;want ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Jan 2019 10:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524796#M4833</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-05T10:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524846#M4846</link>
      <description>&lt;P&gt;Thank you very much for your answer!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jan 2019 21:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524846#M4846</guid>
      <dc:creator>AndreMenezes</dc:creator>
      <dc:date>2019-01-05T21:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Select from the first to the k-th element in a macro list variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524848#M4847</link>
      <description>&lt;P&gt;I appreciate your solution.&lt;BR /&gt;I solved the problem using the %do loop, but I thought there were some function like scan that select the k-th element from a list macro variable.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jan 2019 21:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Select-from-the-first-to-the-k-th-element-in-a-macro-list/m-p/524848#M4847</guid>
      <dc:creator>AndreMenezes</dc:creator>
      <dc:date>2019-01-05T21:33:11Z</dc:date>
    </item>
  </channel>
</rss>

