<?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 how to resolve tailing % within a passing text in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754146#M237765</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help resolving the below code:&lt;/P&gt;&lt;P&gt;%let STP_TEST1= Mean - 1DP - 50 %;&lt;BR /&gt;%let STP_TEST2= Minimum- 1DP - 50 %;&lt;BR /&gt;%let STP_TEST3= Maximum - 1DP - 50 %;&lt;/P&gt;&lt;P&gt;%let STP_TEST_COUNT=3;&lt;/P&gt;&lt;P&gt;%macro build_filter_display(varname);&lt;BR /&gt;(%if &amp;amp;&amp;amp;&amp;amp;varname._Count. eq 1 %then %trim(&amp;amp;&amp;amp;&amp;amp;varname); %else %do i=1 %to &amp;amp;&amp;amp;&amp;amp;varname._Count.; %if &amp;amp;i. NE 1 %then,%str( ); %trim(&amp;amp;&amp;amp;&amp;amp;varname&amp;amp;i.)%end;)&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%macro selection_data;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;length Selection $4000.;&lt;BR /&gt;label Selection="Selection Criteria";&lt;/P&gt;&lt;P&gt;%if (&amp;amp;STP_TEST_COUNT. GT 0) %then&lt;BR /&gt;Selection="Test in %build_filter_display(STP_TEST)" %str(;) Output%str(;);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%selection_data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;above code is outputting as&lt;/P&gt;&lt;P&gt;Test in (Mean - 1DP - 50 %2 NE 1 , Minimum- 1DP - 50 %3 NE 1 , Maximum - 1DP - 50 %)&lt;/P&gt;&lt;P&gt;I want it as&lt;/P&gt;&lt;P&gt;Test in (Mean - 1DP - 50 % , Minimum- 1DP - 50 % , Maximum - 1DP - 50 %)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Bhanu&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jul 2021 18:16:32 GMT</pubDate>
    <dc:creator>BBP</dc:creator>
    <dc:date>2021-07-14T18:16:32Z</dc:date>
    <item>
      <title>how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754146#M237765</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help resolving the below code:&lt;/P&gt;&lt;P&gt;%let STP_TEST1= Mean - 1DP - 50 %;&lt;BR /&gt;%let STP_TEST2= Minimum- 1DP - 50 %;&lt;BR /&gt;%let STP_TEST3= Maximum - 1DP - 50 %;&lt;/P&gt;&lt;P&gt;%let STP_TEST_COUNT=3;&lt;/P&gt;&lt;P&gt;%macro build_filter_display(varname);&lt;BR /&gt;(%if &amp;amp;&amp;amp;&amp;amp;varname._Count. eq 1 %then %trim(&amp;amp;&amp;amp;&amp;amp;varname); %else %do i=1 %to &amp;amp;&amp;amp;&amp;amp;varname._Count.; %if &amp;amp;i. NE 1 %then,%str( ); %trim(&amp;amp;&amp;amp;&amp;amp;varname&amp;amp;i.)%end;)&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%macro selection_data;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;length Selection $4000.;&lt;BR /&gt;label Selection="Selection Criteria";&lt;/P&gt;&lt;P&gt;%if (&amp;amp;STP_TEST_COUNT. GT 0) %then&lt;BR /&gt;Selection="Test in %build_filter_display(STP_TEST)" %str(;) Output%str(;);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%selection_data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;above code is outputting as&lt;/P&gt;&lt;P&gt;Test in (Mean - 1DP - 50 %2 NE 1 , Minimum- 1DP - 50 %3 NE 1 , Maximum - 1DP - 50 %)&lt;/P&gt;&lt;P&gt;I want it as&lt;/P&gt;&lt;P&gt;Test in (Mean - 1DP - 50 % , Minimum- 1DP - 50 % , Maximum - 1DP - 50 %)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Bhanu&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 18:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754146#M237765</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-14T18:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754150#M237767</link>
      <description>&lt;P&gt;Can you explain what you are trying to do?&lt;/P&gt;
&lt;P&gt;Show the SAS code you are trying to use the macro code to generate.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 18:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754150#M237767</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-14T18:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754157#M237768</link>
      <description>&lt;P&gt;Did you try wrapping it in %str in the %let statement?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let STP_TEST1= %str(Mean - 1DP - 50 %);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jul 2021 19:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754157#M237768</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-14T19:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754177#M237776</link>
      <description>&lt;P&gt;Below macro returns what you're asking for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let STP_text1= Mean - 1DP - 50 %;
%let STP_text2= Minimum- 1DP - 50 %;
%let STP_text3= Maximum - 1DP - 50 %;
%let STP_text_COUNT=3;

%macro build_filter_display(varname);
  %local text;
  %do i=1 %to &amp;amp;&amp;amp;&amp;amp;varname._COUNT;
    %if &amp;amp;i= 1 %then
      %let text=%nrstr(&amp;amp;&amp;amp;&amp;amp;varname).&amp;amp;i;
    %else
      %let text=&amp;amp;text, %nrstr(&amp;amp;&amp;amp;&amp;amp;varname).&amp;amp;i;
  %end;
  %unquote(&amp;amp;text)
%mend;

data text;
  length Selection $4000.;
  label Selection="Selection Criteria";
  if &amp;amp;STP_text_COUNT &amp;gt; 0 then
    do;
      Selection="text in (%build_filter_display(STP_text))";
      output;
    end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1626295370015.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61263iCB40D3EE4B07B8FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1626295370015.png" alt="Patrick_0-1626295370015.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 20:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754177#M237776</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-14T20:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754192#M237784</link>
      <description>&lt;P&gt;Either spend some time adding macro quoting in your macro to protect the generated text:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro build_filter_display(varname);
%local i mvar sep;
(%do i=1 %to &amp;amp;&amp;amp;&amp;amp;varname._count;
  %let mvar=&amp;amp;varname.&amp;amp;i;&amp;amp;sep.%superq(&amp;amp;mvar)%let sep=%str( , );
%end;)
%mend build_filter_display;

%put "Test in %build_filter_display(stp_test)" ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or since you use the value in SAS code use regular SAS code instead of macro code to generate the value you want from that list of macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let basename=STP_TEST;
data test;
  length Selection $4000.;
  label Selection="Selection Criteria";
  do i=1 to symgetn("&amp;amp;basename._count");
     selection=catx(' , ',selection,symget(cats("&amp;amp;basename",i)));
  end;
  selection=cats('Test in (',selection,')');
  put selection= $quote.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 22:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754192#M237784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-14T22:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754256#M237809</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;Patrick, your code resolved bit of my requirement, now I need the values in quotes, for that I have used following code:&lt;/P&gt;&lt;P&gt;%macro build_filter_display(varname);&lt;BR /&gt;(&lt;BR /&gt;%let test=;&lt;BR /&gt;%do i = 1 %to &amp;amp;&amp;amp;&amp;amp;varname._Count.;&lt;BR /&gt;%if &amp;amp;i = 1 %then&lt;BR /&gt;%if %nrbquote(%trim(&amp;amp;&amp;amp;&amp;amp;varname)) eq %nrbquote() %then '-1';&lt;BR /&gt;%else %let test=%trim(%nrstr(%")%nrstr(%trim(&amp;amp;&amp;amp;&amp;amp;varname)).%nrstr(%"));&lt;BR /&gt;%else&lt;BR /&gt;%if %nrbquote(%trim(&amp;amp;&amp;amp;&amp;amp;varname&amp;amp;i.)) eq %nrbquote() %then '-1';&lt;BR /&gt;%else&lt;BR /&gt;%let test=&amp;amp;test,%str( )%nrstr(%")%trim(%nrstr(&amp;amp;&amp;amp;&amp;amp;varname).&amp;amp;i)%nrstr(%");&lt;BR /&gt;%end;&lt;BR /&gt;%unquote(&amp;amp;test)&lt;BR /&gt;)&lt;BR /&gt;%mend;&lt;BR /&gt;/*%build_in_statement_oracle2;*/&lt;BR /&gt;%put Test in %build_in_statement_oracle(STP_TEST);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which is generating outcome as:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BBP_0-1626342091630.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61266iF999F189517ECEFC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BBP_0-1626342091630.png" alt="BBP_0-1626342091630.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;may be that highlighted bit causing issue in my oracle query&lt;/P&gt;&lt;P&gt;MPRINT(BUILD_FILTER_DISPLAY): (&lt;BR /&gt;MPRINT(BUILD_FILTER_DISPLAY): "BA - Label Claim - Mean - 1DP - 50 %","BA - Label Claim - Minimum- 1DP - 50 %","BA - Label Claim - Maximum - 1DP - 50 %" )&lt;/P&gt;&lt;P&gt;ERROR: ORA-00972: identifier is too long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 09:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754256#M237809</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-15T09:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754272#M237818</link>
      <description>Hi Patrick,&lt;BR /&gt;Please ignore above request, the error is because of double quotes.&lt;BR /&gt;Thanks,&lt;BR /&gt;Bhanu</description>
      <pubDate>Thu, 15 Jul 2021 11:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754272#M237818</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-15T11:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754275#M237821</link>
      <description>Thanks Tom</description>
      <pubDate>Thu, 15 Jul 2021 11:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754275#M237821</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-15T11:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754276#M237822</link>
      <description>Thank you!</description>
      <pubDate>Thu, 15 Jul 2021 11:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754276#M237822</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-15T11:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754645#M238027</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AS I mentioned the gap before the values is returning no data in further steps. is there any way to remove spaces before the values?&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;Bhanu&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 17:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754645#M238027</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-16T17:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754647#M238028</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your macro works but sometimes when COUNT = 1 then we have value with no suffix. for example&lt;/P&gt;&lt;P&gt;%let STUDYID=S_12345;&lt;BR /&gt;%let STUDYID_COUNT=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this case your macro is not working, I prefer macro than data step, any help appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bhanu&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754647#M238028</guid>
      <dc:creator>BBP</dc:creator>
      <dc:date>2021-07-16T18:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754649#M238030</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335936"&gt;@BBP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;your macro works but sometimes when COUNT = 1 then we have value with no suffix. for example&lt;/P&gt;
&lt;P&gt;%let STUDYID=S_12345;&lt;BR /&gt;%let STUDYID_COUNT=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in this case your macro is not working, I prefer macro than data step, any help appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Bhanu&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have seen that inconsistent behavior mentioned before.&amp;nbsp; Here is modification to fix it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically just make sure that the suffix 1 variable exists by copying the value of the variable without a suffix.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro build_filter_display(varname);
%local i mvar sep;
%if &amp;amp;&amp;amp;&amp;amp;varname._count = 1 %then %let &amp;amp;varname.1=%superq(&amp;amp;varname);
(%do i=1 %to &amp;amp;&amp;amp;&amp;amp;varname._count;
  %let mvar=&amp;amp;varname.&amp;amp;i;&amp;amp;sep.%superq(&amp;amp;mvar)%let sep=%str( , );
%end;)
%mend build_filter_display;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754649#M238030</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-16T18:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to resolve tailing % within a passing text in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754650#M238031</link>
      <description>&lt;P&gt;When emitting a series of text in a macro to be used as a string you can make sure that no separating spaces are generated by not including white space around the text to be emit.&amp;nbsp; For example by adding some macro comments.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%*;&amp;amp;mvar%*;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resolve-tailing-within-a-passing-text-in-macro/m-p/754650#M238031</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-16T18:18:13Z</dc:date>
    </item>
  </channel>
</rss>

