<?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: Removing from a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100911#M21125</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%macro test;


%let group=country state city county;
%put &amp;amp;group;

%let i=%sysfunc(countw(&amp;amp;group));
%let temp=%scan(&amp;amp;group,&amp;amp;i);
%let group=%sysfunc(tranwrd(&amp;amp;group,&amp;amp;temp,%str( )));
%do %while(&amp;amp;i ge 2);
%put &amp;amp;group;
%let i=%eval(&amp;amp;i-1);
%let temp=%scan(&amp;amp;group,&amp;amp;i);
%let group=%sysfunc(tranwrd(&amp;amp;group,&amp;amp;temp,%str( )));
%end;


%mend test;

%test

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 May 2012 05:37:41 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-05-03T05:37:41Z</dc:date>
    <item>
      <title>Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100905#M21119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having&amp;nbsp; a macro variable&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let group=country state city county&lt;/P&gt;&lt;P&gt;for each iteration i need to remove the last one and use it as a group item&lt;/P&gt;&lt;P&gt;i have to 3 iterations&lt;/P&gt;&lt;P&gt;when i=1&lt;/P&gt;&lt;P&gt;&amp;amp;group=country state city&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;creat table test1&lt;/P&gt;&lt;P&gt;select *,sum(pop)&lt;/P&gt;&lt;P&gt;from tes1&lt;/P&gt;&lt;P&gt;group by &amp;amp;group&lt;/P&gt;&lt;P&gt;when i=2&lt;/P&gt;&lt;P&gt;&amp;amp;group=country state&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want create a macro variable like that.i want to use that macro variable in grouping sql.&lt;/P&gt;&lt;P&gt;i tried using %scan but i am duno know how to handle the remaining value of the string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can some one help me out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 13:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100905#M21119</guid>
      <dc:creator>JasonNC</dc:creator>
      <dc:date>2012-05-02T13:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100906#M21120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jason,&lt;BR /&gt;You can try using the following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let vars=country state city county;&lt;/P&gt;&lt;P&gt;%do i=1 %to 3;&lt;/P&gt;&lt;P&gt;%let group=%substr(&amp;amp;vars,1,%eval(&amp;nbsp; %index(&amp;amp;vars,&amp;nbsp; %scan(&amp;amp;vars,%eval(5-&amp;amp;i))&amp;nbsp; )-1)&amp;nbsp; );&lt;/P&gt;&lt;P&gt;%put &amp;amp;group;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The nested functions can be a little hard to follow. Using another %do loop and concatenating the variables(%let group=&amp;amp;group %scan(&amp;amp;vars,&amp;amp;j) ) might be a better option if you want to improve readability of the program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 18:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100906#M21120</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2012-05-02T18:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100907#M21121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RIck,&lt;/P&gt;&lt;P&gt;Thanks for replying.I got it .Anways i did the same way nested code.previously i did a small mistake.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am trying to insert ,using tranwrd function but it is not working in %sysfunc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let group1=%sysfunc(tranwrd("&amp;amp;group",' ' , ',');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it is not inserting , between the values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 19:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100907#M21121</guid>
      <dc:creator>JasonNC</dc:creator>
      <dc:date>2012-05-02T19:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100908#M21122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let group=country state city;&lt;/P&gt;&lt;P&gt;%let group1=%sysfunc( tranwrd( &amp;amp;group, %str( ),%str(,) ));&lt;/P&gt;&lt;P&gt;%put &amp;amp;group1;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 20:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100908#M21122</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-05-02T20:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100909#M21123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jason,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps it is possible that you are solving this problem the wrong way.&amp;nbsp; You can get the sums of POP at various levels in one step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=tes1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; class state county city;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; var pop;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=test1 sum=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the ID statement to bring in other variables if needed, and another statement that I forget off the top of my head to obtain just some of the levels of summarization instead of all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At any rate, PROC SUMMARY with a CLASS statement is definitely a tool you should have in your arsenal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good lucki.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 20:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100909#M21123</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-02T20:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100910#M21124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also&lt;/P&gt;&lt;P&gt;%let group1=%sysfunc( translate( &amp;amp;group, ',' , ' ' ));&lt;/P&gt;&lt;P&gt;works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 20:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100910#M21124</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2012-05-02T20:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Removing from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100911#M21125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%macro test;


%let group=country state city county;
%put &amp;amp;group;

%let i=%sysfunc(countw(&amp;amp;group));
%let temp=%scan(&amp;amp;group,&amp;amp;i);
%let group=%sysfunc(tranwrd(&amp;amp;group,&amp;amp;temp,%str( )));
%do %while(&amp;amp;i ge 2);
%put &amp;amp;group;
%let i=%eval(&amp;amp;i-1);
%let temp=%scan(&amp;amp;group,&amp;amp;i);
%let group=%sysfunc(tranwrd(&amp;amp;group,&amp;amp;temp,%str( )));
%end;


%mend test;

%test

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 May 2012 05:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-from-a-macro-variable/m-p/100911#M21125</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-05-03T05:37:41Z</dc:date>
    </item>
  </channel>
</rss>

