<?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: FCMP: Multiple arrays simplification in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766592#M242966</link>
    <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43088" target="_blank"&gt;adil256&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your array values differ by sign (+ or -) only, you can use a single array, f, defined once at the top (not inside if-then-do) and have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Product="A" then return ( f[Sex,Smoker,Type_Tariff]);
else if Product="B" then return ( -f[Sex,Smoker,Type_Tariff]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Would that help?&lt;/P&gt;</description>
    <pubDate>Wed, 08 Sep 2021 14:34:07 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2021-09-08T14:34:07Z</dc:date>
    <item>
      <title>FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766580#M242959</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'd like to simplify my function by using only 1 array name so I can avoid to use an 'if then' statement at the end:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Get Tarif Paramaters*/
proc fcmp outlib=mydata.functions.func;
function Get_Parameter(Product $, Sex,Smoker,Type_Tariff); /* Sex = 1 or 2, Smoker =1 or 2 , Type_Tariff= 1 or 2 */
if Product="A" then
do;
array f[2,2,2] (4 3,
                2 1,
                8 7,
                6 5);
end;

else if Product="B" then
do;
array q[2,2,2] (-4 -3,
                -2 -1,
                -8 -7,
                -6 -5);
end;

if Product="A" then
return ( f[Sex,Smoker,Type_Tariff]);
else if Product="B" then
return ( q[Sex,Smoker,Type_Tariff]);
endsub;

Data paramater;
do product= "A" ,"B";
do Sex=1 to 2;
do Smoker=1 to 2;
do Type_Tariff=1 to 2;
a=Get_Parameter(product,Sex,Smoker,Type_Tariff);
output;
end;
end;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I want but it doesn't work because I can't have the same array name for 2 different vectors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Get Tarif Paramaters*/
proc fcmp outlib=mydata.functions.func;
function Get_Parameter(Product $, Sex,Smoker,Type_Tariff); /* Sex = 1 or 2, Smoker =1 or 2 , Type_Tariff= 1 or 2 */
if Product="A" then
do;
array f[2,2,2] (4 3,
                2 1,
                8 7,
                6 5);
end;

else if Product="B" then
do;
array f[2,2,2] (-4 -3,
                -2 -1,
                -8 -7,
                -6 -5);
end;

return ( f[Sex,Smoker,Type_Tariff]);
endsub;

Data paramater;
do product= "A" ,"B";
do Sex=1 to 2;
do Smoker=1 to 2;
do Type_Tariff=1 to 2;
a=Get_Parameter(product,Sex,Smoker,Type_Tariff);
output;
end;
end;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;thank u for ur help&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 14:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766580#M242959</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2021-09-08T14:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766591#M242965</link>
      <description>&lt;P&gt;Just add another dimension to your array and convert the A and B into integers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 14:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766591#M242965</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-08T14:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766592#M242966</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43088" target="_blank"&gt;adil256&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your array values differ by sign (+ or -) only, you can use a single array, f, defined once at the top (not inside if-then-do) and have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Product="A" then return ( f[Sex,Smoker,Type_Tariff]);
else if Product="B" then return ( -f[Sex,Smoker,Type_Tariff]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Would that help?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 14:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766592#M242966</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-09-08T14:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766593#M242967</link>
      <description>&lt;P&gt;I thought about this solution but it's quite inconvenient when u have a lot of different product. I only use 2 products in my example to simply my demand. Moreover, I need to perform some calculations on the array for some of the products.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx anyway for ur help&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 14:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766593#M242967</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2021-09-08T14:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766614#M242976</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51532"&gt;@LeonidBatkhan&lt;/a&gt;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately&lt;SPAN&gt;&amp;nbsp;not, I can have different values in the array so I could not take the negative. ^^&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thx for ur help though. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 15:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766614#M242976</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2021-09-08T15:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766618#M242978</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43088"&gt;@adil256&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I thought about this solution but it's quite inconvenient when u have a lot of different product. I only use 2 products in my example to simply my demand. Moreover, I need to perform some calculations on the array for some of the products.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thx anyway for ur help&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is there any reason why you are trying to use a function?&lt;/P&gt;
&lt;P&gt;Why are you storing the data into a program to begin with?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not store the data into a dataset?&lt;/P&gt;
&lt;P&gt;Then you could just use a index and set statement to retrieve the values.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 15:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766618#M242978</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-08T15:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766624#M242980</link>
      <description>&lt;P&gt;Why put data into a function?&lt;BR /&gt;Why use a function at all?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup (index=(multi=(product sex smoker Type_Tariff)));
do product= "A" ,"B";
do Sex=1 to 2;
do Smoker=1 to 2;
do Type_Tariff=1 to 2;
  input a @@;
  output;
end;
end;
end;
end;
cards;
 4  3     2  1    8  7    6  5
-4 -3    -2 -1   -8 -7   -6 -5
;;;;

data parameter;
do product= "A" ,"B";
do Sex=1 to 2;
do Smoker=1 to 2;
do Type_Tariff=1 to 2;
  set lookup key=multi/unique ;
  output;
end;
end;
end;
end;
stop;
run;

proc compare data=lookup compare=parameter;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Sep 2021 15:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766624#M242980</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-08T15:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP: Multiple arrays simplification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766628#M242983</link>
      <description>&lt;P&gt;Because I don't know where to begin with a datastep.&lt;/P&gt;&lt;P&gt;I know I can use a Proc Sql and merge with the dataset containing the values but I'm not a huge fan of this methodology.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could u tell me more about your solution with an index?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 15:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-Multiple-arrays-simplification/m-p/766628#M242983</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2021-09-08T15:40:40Z</dc:date>
    </item>
  </channel>
</rss>

