<?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: Can we create array inside a sas macro and use it ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556818#M155144</link>
    <description>&lt;P&gt;Take your percentile data and convert it to a format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data percentiles;
  input  _NAME_ $ Percentile @@ ;
cards;
 P_0 -10  P_1 -5  P_2 0  P_3 5  P_4 10  P_5 15
 P_6 17  P_7 21  P_8 25  P_9 30  P_10 34
;
data formats;
retain fmtname 'rank';
  set percentiles;
  label=_name_;
  end=percentile;
  start=lag(percentile);
  if missing(start) then hlo='L';
  keep fmtname start end label hlo;
run;

proc format cntlin=formats ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use the format to encode your actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input factor1 expected $ @@ ;
cards;
10 P_4 15 P_5 21 P_7 -8 P_0
4 P_3 -3 P_1 33 P_10
;

data want;
  set have ;
  percentile=put(factor1,rank.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    factor1    expected    percentile

 1        10        P_4          P_4
 2        15        P_5          P_5
 3        21        P_7          P_7
 4        -8        P_0          P_1
 5         4        P_3          P_3
 6        -3        P_1          P_2
 7        33        P_10         P_10&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 May 2019 15:36:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-07T15:36:12Z</dc:date>
    <item>
      <title>Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556033#M154826</link>
      <description>&lt;P&gt;I have column value (Factor 1) which I need to compare with 1 to 100 percentile values to determine under which bucket it fall.&lt;/P&gt;&lt;P&gt;Iteratively I have to perform this comparision for all the row in my column/factor 1 ?&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 17:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556033#M154826</guid>
      <dc:creator>Sujaytalesara</dc:creator>
      <dc:date>2019-05-03T17:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556072#M154850</link>
      <description>&lt;P&gt;Without seeing a portion of your actual data, I cannot provide more specific advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, PROC RANK can do this. If you use the GROUPS=100 option, each observation is placed into the proper percentile. No arrays or macros needed.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556072#M154850</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-03T19:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556723#M155112</link>
      <description>&lt;P&gt;Thanks Paige&amp;nbsp; for your response.&lt;/P&gt;&lt;P&gt;In table 1, I have a column value (Factor 1) which I need to compare from percentile values from table 2 ( which contains)1 to 100 percentile values) and create a column in table 1 to store the percentile bucket (eg. added in below table 1)&amp;nbsp;under which&amp;nbsp;the values&amp;nbsp;falls ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Iteratively I have to perform this comparision for all the row in my column/factor 1 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Table 1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Factor 1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Percentile Bucket&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;P_4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;P_5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;P_7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;-8&lt;/TD&gt;&lt;TD&gt;P_0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;P_3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;-3&lt;/TD&gt;&lt;TD&gt;P_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;33&lt;/TD&gt;&lt;TD&gt;P_10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Table 2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;_NAME_&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Percentile &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_0&lt;/TD&gt;&lt;TD&gt;-10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_1&lt;/TD&gt;&lt;TD&gt;-5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_3&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_4&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_5&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_6&lt;/TD&gt;&lt;TD&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_7&lt;/TD&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_8&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_9&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;P_10&lt;/TD&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 07 May 2019 10:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556723#M155112</guid>
      <dc:creator>Sujaytalesara</dc:creator>
      <dc:date>2019-05-07T10:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556735#M155116</link>
      <description>&lt;P&gt;Macros and arrays and iteration are not necessary here. Nevertheless, let me ask one more question: if Factor 1 equals 23, you have a tie between P_7 and P_8, what should the answer be in that case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are willing to accept a default answer, then &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt; has the answer:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Finding-closest-value/td-p/352655" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Finding-closest-value/td-p/352655&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 12:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556735#M155116</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-07T12:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556763#M155121</link>
      <description>&lt;P&gt;I already have a macro and wanted to add this functionality to the exisiting one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comming to your question, if the factor_1 has value 23 then it will fall under P_8.&lt;/P&gt;&lt;P&gt;The condition I am using here is - &amp;nbsp;if (P_7&amp;lt; Factor_1 &amp;lt;= P_8) then P_8 and so will apply for all values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how it could be done without array's as for each value in table 1&amp;nbsp;I am required to&amp;nbsp;iterate over all the values of table 2.&lt;/P&gt;&lt;P&gt;Would be great if you can help me out here ! Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 13:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556763#M155121</guid>
      <dc:creator>Sujaytalesara</dc:creator>
      <dc:date>2019-05-07T13:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556774#M155123</link>
      <description>&lt;P&gt;The answer I linked to still works, you just have to change the condition so that it covers the case where&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;if (P_7&amp;lt; Factor_1 &amp;lt;= P_8) then P_8&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So, untested code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
    select b.factor1,a._name_
      from table2 a, table1 b
      group by b.factor1
        having (b.factor1-a.percentile) eq min(b.factor1-a.percentile) and 
             (b.factor1-a.percentile)&amp;lt;=0
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 13:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556774#M155123</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-07T13:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556776#M155125</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236360"&gt;@Sujaytalesara&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have column value (Factor 1) which I need to compare with 1 to 100 percentile values to determine under which bucket it fall.&lt;/P&gt;
&lt;P&gt;Iteratively I have to perform this comparision for all the row in my column/factor 1 ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure why macro would be needed for any implementation of this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could just join the tables and figure out the percentile.&lt;/P&gt;
&lt;P&gt;You could convert the percentile table into a format and use the format to group the other variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where you might get value from macro coding is if you wanted to apply the same functionality to multiple datasets with different variable names.&amp;nbsp; But before you can work on making a macro make sure you know what SAS code you want it to generate.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 13:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556776#M155125</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-07T13:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556806#M155138</link>
      <description>&lt;P&gt;Sorry but this way it does not work.&lt;/P&gt;&lt;P&gt;Inside having condition, the value of &amp;nbsp;&lt;EM&gt;&lt;SPAN class="token function"&gt;min&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;factor1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;percentile&lt;/EM&gt;&lt;SPAN class="token punctuation"&gt;&lt;EM&gt;)&lt;/EM&gt; cannot be computed corrected as every time during the substraction and with min () condition the factor_1 will be substracted with the highest value ie. of P_100 (value 507)&amp;nbsp;which yeild a value&amp;nbsp;-455 and thus every time P_100 percentile band will be selected.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&amp;nbsp;Example - &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Factor 1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_42&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_43&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_75&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_76&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_77&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_97&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_98&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_99&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;152&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-431&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-246&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-209&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;26&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;30&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;149&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;154&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;159&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;320&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;346&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;379&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;507&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;28&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-431&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-246&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-209&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;26&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;30&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;149&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;154&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;159&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;320&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;346&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;379&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;507&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;In the above table, the correct percentile band of 152 should be P_75 (value 154) and 28 should be P_43 but using your mentioned query it gives &lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Factor 1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;_NAME_&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;COL1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;152&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_100&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;507&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;28&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;P_100&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;507&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;What&amp;nbsp;I need is comparing the value of factor_1 with each percentile value and find the percentile bucket in which the factor_1 value is less than or equal to. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Why I have been using array is bcoz I have been used to Object oriented language and with array its easy to compare Factor_1 value iteratively with every single percentile value and saving the index where it matches -- this is how I am doing&amp;nbsp; and as it is a part of a process chain it needs to be run within pre-defined macro&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS code for calculating the percentile band but does not work under macro as I am unable to figure out arrays inside macro -&lt;BR /&gt;data data_band2 ;&lt;/P&gt;&lt;P&gt;set data;&lt;/P&gt;&lt;P&gt;array p{*} P_0 - P_100;&lt;/P&gt;&lt;P&gt;score_perc = 0;&lt;/P&gt;&lt;P&gt;do i = 1 to 100;&lt;/P&gt;&lt;P&gt;if Factor_1 &amp;gt; p{i} and Factor_1 &amp;lt;= p{i+1} then&lt;/P&gt;&lt;P&gt;score_perc = i;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if Factor_1 &amp;lt; P_1 then score_perc=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 15:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556806#M155138</guid>
      <dc:creator>Sujaytalesara</dc:creator>
      <dc:date>2019-05-07T15:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556818#M155144</link>
      <description>&lt;P&gt;Take your percentile data and convert it to a format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data percentiles;
  input  _NAME_ $ Percentile @@ ;
cards;
 P_0 -10  P_1 -5  P_2 0  P_3 5  P_4 10  P_5 15
 P_6 17  P_7 21  P_8 25  P_9 30  P_10 34
;
data formats;
retain fmtname 'rank';
  set percentiles;
  label=_name_;
  end=percentile;
  start=lag(percentile);
  if missing(start) then hlo='L';
  keep fmtname start end label hlo;
run;

proc format cntlin=formats ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use the format to encode your actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input factor1 expected $ @@ ;
cards;
10 P_4 15 P_5 21 P_7 -8 P_0
4 P_3 -3 P_1 33 P_10
;

data want;
  set have ;
  percentile=put(factor1,rank.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    factor1    expected    percentile

 1        10        P_4          P_4
 2        15        P_5          P_5
 3        21        P_7          P_7
 4        -8        P_0          P_1
 5         4        P_3          P_3
 6        -3        P_1          P_2
 7        33        P_10         P_10&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 15:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556818#M155144</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-07T15:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556820#M155145</link>
      <description>&lt;P&gt;Ok, at this point you need to provide us your data as a SAS data step, as explained here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way we can work with your exact data, instead of looking at tables that you include in your posts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still contend that if your data is structured as in your original data table (and not in the latest data table), then the code I provided will work. But until we have your actual data as a SAS data step (and not in any other format), I can't provide code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 15:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/556820#M155145</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-07T15:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can we create array inside a sas macro and use it ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/557155#M155278</link>
      <description>&lt;P&gt;Woow ! Thanks a million Tom. It worked exactly.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 15:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-create-array-inside-a-sas-macro-and-use-it/m-p/557155#M155278</guid>
      <dc:creator>Sujaytalesara</dc:creator>
      <dc:date>2019-05-08T15:12:15Z</dc:date>
    </item>
  </channel>
</rss>

