<?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: Parsing a variable number of parameters in a SAS/IML module in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764529#M5618</link>
    <description>&lt;P&gt;Is your example what you WANT or what you DON'T want? Please post an example of what you WANT, along with examples of calling the function and what you expect the function to do for each call.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Aug 2021 17:52:06 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2021-08-27T17:52:06Z</dc:date>
    <item>
      <title>Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764524#M5617</link>
      <description>&lt;P&gt;I want to parse the arguments to a SAS/IML module independently of using the predefined "name=value" schema, which limits me to defining all of the name/value pairs that I may want to use. For example,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;start example( control_parameter, var1=value1, var2=value2, ..., varN=valueN ) ;

/* parse the argument list and process the parameters according to the control_parameter,&lt;BR /&gt; * which defines the operations to perform on the argument variables var1, ..., varN&lt;BR /&gt; */&lt;BR /&gt;finish&amp;nbsp;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This would give me a capability similar to MATLAB's nargin variable and SAS/MACRO's &amp;amp;SYSPARM representation of an argument vector. Is there a SAS/IML function that I can use to parse the argument string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, is there a SAS/IML equivalent of the base SAS SELECT construct, or must I use repeated IF-THEN-ELSE statements?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 17:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764524#M5617</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-08-27T17:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764529#M5618</link>
      <description>&lt;P&gt;Is your example what you WANT or what you DON'T want? Please post an example of what you WANT, along with examples of calling the function and what you expect the function to do for each call.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 17:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764529#M5618</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-08-27T17:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764539#M5619</link>
      <description>&lt;P&gt;I want to parse the arguments to a SAS/IML module independently of using the predefined "name=value" schema, which limits me to defining all of the name/value pairs that I may want to use. For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;start example( var1=value1, var2=value2, ..., varN=valueN ) ;

/* Let us assume that there is a SAS/IML function called "getopt" (like the C language getopt() function) that will return a name/value pair */&lt;/CODE&gt;&lt;BR /&gt;/* then we could write code like this: */&lt;BR /&gt;&lt;BR /&gt;do while( 1 ) ;&lt;BR /&gt;variableNameValuePair = getopt() ;&lt;BR /&gt;if isEmpty( variableNameValuePair ) then leave ;&lt;BR /&gt;varName = scan( variableNameValuePair, 1 ) ; varValue = scan( variableNameValuePair, 2 ) ;&lt;BR /&gt;/* perform further processing based on contents of varName, e.g., store varValue in list item L$varname */&lt;BR /&gt;end ;&lt;BR /&gt;&lt;BR /&gt;finish ;&lt;/PRE&gt;&lt;P&gt;This would give me a capability similar to MATLAB's nargin variable and SAS/MACRO's &amp;amp;SYSPARM representation of an argument vector. Is there a SAS/IML function that I can use to parse the argument string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, is there a SAS/IML equivalent of the base SAS SELECT construct, or must I use repeated IF-THEN-ELSE statements?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 18:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764539#M5619</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-08-27T18:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764547#M5620</link>
      <description>&lt;P&gt;I would pass in a named list. You can query to list to find out how many items it has. You can use &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_013/imlug/imlug_langref_sect240.htm" target="_self"&gt;the LISTGETALLNAMES function&lt;/A&gt; to get the keywords that are passed in. You can then use the ListGetItem function to get the values for the keywords that are present in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding SELECT-WHEN: That syntax is used for SCALAR values in the DATA step. In IML, use the LOC function to identify values and then process those elements however you want. For example, the following programs compare the SELECT-WHEN statement in the DATA step to using the LOC function in IML:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* example of using the SELECT statement */
data Heart1;
set sashelp.heart;
select (Smoking_Status);
   when ('Non-smoker')        Smoking_Cat=1;
   when ('Light (1-5)')       Smoking_Cat=2;
   when ('Moderate (6-15)')   Smoking_Cat=3;
   when ('Heavy (16-25)')     Smoking_Cat=4;
   when ('Very Heavy (&amp;gt; 25)') Smoking_Cat=5;
   otherwise                  Smoking_Cat=.;
end;
run;


proc iml;
use sashelp.heart;
read all var "Smoking_Status";
close;

case={'Non-smoker' 'Light (1-5)' 'Moderate (6-15)' 'Heavy (16-25)' 'Very Heavy (&amp;gt; 25)'};
result = {1 2 3 4 5};

Smoking_Cat = j(nrow(Smoking_Status), 1, .);
do i = 1 to ncol(case);
   idx = loc(Smoking_Status=case[i]);
   if ncol(idx)&amp;gt;0 then 
      Smoking_Cat[idx]=result[i];
end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Aug 2021 19:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764547#M5620</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-08-27T19:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764550#M5621</link>
      <description>&lt;P&gt;Both answers are very nice solutions to my questions. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 19:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764550#M5621</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-08-27T19:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764616#M5622</link>
      <description>&lt;P&gt;Also could try PROC FORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue fmt
   'Non-smoker'       =1
   'Light (1-5)'       =2
   'Moderate (6-15)'   =3
   'Heavy (16-25)'    =4
   'Very Heavy (&amp;gt; 25)' =5
;
run;


proc iml;
use sashelp.heart(obs=100);
read all var "Smoking_Status";
close;  
Smoking_Cat=j(nrow(Smoking_Status),1,.);
Smoking_Cat=inputn(Smoking_Status,'fmt.');

print Smoking_Status Smoking_Cat ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Aug 2021 12:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764616#M5622</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-28T12:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a variable number of parameters in a SAS/IML module</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764626#M5623</link>
      <description>Very interesting idea. Thank you for your insight.&lt;BR /&gt;</description>
      <pubDate>Sat, 28 Aug 2021 13:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Parsing-a-variable-number-of-parameters-in-a-SAS-IML-module/m-p/764626#M5623</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-08-28T13:49:11Z</dc:date>
    </item>
  </channel>
</rss>

