<?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: Passing a vector of strings as an argument to an IML function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125177#M951</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did a little more investigation, my code above does return a 3x1 text matrix, but the second and third elements are blank.&amp;nbsp; (Rick can you investigate this please?).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Sep 2012 10:07:48 GMT</pubDate>
    <dc:creator>IanWakeling</dc:creator>
    <dc:date>2012-09-20T10:07:48Z</dc:date>
    <item>
      <title>Passing a vector of strings as an argument to an IML function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125175#M949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have defined an IML function which takes 2 arguments : one as numeric, the other as character.&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; age_vect=J(10,1,10);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text_vect=J(10,1,"YES");&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start test(age,text);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if text="NO" then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp=age+0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if text="YES" then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp=age+10;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(temp);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; finish test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result_1=test(10,"YES");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result_2=apply("test",age_vect,text_vect);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;I want to apply this function to vectors, but it doesn't work (Result_2).&lt;/P&gt;&lt;P&gt;But this function will work if i try to calculate Result_1.&lt;/P&gt;&lt;P&gt;Is it impossible to pass vectors of characters to IML function?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2012 11:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125175#M949</guid>
      <dc:creator>Dima</dc:creator>
      <dc:date>2012-09-19T11:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a vector of strings as an argument to an IML function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125176#M950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the answer may be that&amp;nbsp; the APPLY function is not designed to work with modules that take text arguments, however it doesn't always make this clear.&amp;nbsp;&amp;nbsp; For example the following code runs without error but returns a text matrix with a single element.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start uc(t);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return(upcase(t));&lt;BR /&gt;finish;&lt;/P&gt;&lt;P&gt;cin={"a","b","c"};&lt;BR /&gt;cout=apply("uc",cin);&lt;BR /&gt;print cout;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a look at the CHOOSE function as it can be used to get what you want without writing a module.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result_2=choose(text_vect="YES", age_vect+10, age_vect);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2012 08:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125176#M950</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2012-09-20T08:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a vector of strings as an argument to an IML function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125177#M951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did a little more investigation, my code above does return a 3x1 text matrix, but the second and third elements are blank.&amp;nbsp; (Rick can you investigate this please?).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2012 10:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125177#M951</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2012-09-20T10:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a vector of strings as an argument to an IML function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125178#M952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your suggestion about the CHOOSE function that I didn't know before. It could be helpful but not in my case.&lt;/P&gt;&lt;P&gt;The code above is not what I really want to do, my function is much more complex so I can't find an equivalent using CHOOSE function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the moment, I make my function work by coding as numbers the different strings I want to pass to my function. But that way, the code is less understandable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2012 11:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125178#M952</guid>
      <dc:creator>Dima</dc:creator>
      <dc:date>2012-09-20T11:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a vector of strings as an argument to an IML function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125179#M953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The APPLY function is really nothing more than an implied loop over all the elements of a matrix, so instead of your suggested approach, you could write an explicit loop over each element.&amp;nbsp; Along the lines of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;new_age=age_vect;&lt;/P&gt;&lt;P&gt;do i=1 to nrow(text_vect);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if text_vect&lt;I&gt;="YES"&amp;nbsp; then new_age&lt;I&gt;=new_age&lt;I&gt;+10;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2012 12:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125179#M953</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2012-09-20T12:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a vector of strings as an argument to an IML function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125180#M954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree that there seems to be a problem with calling APPLY with character arguments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's no need to recode anything: just use a loop to call the scalar function that you've already written. It's not as general, but it should work adequately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start MyApply(age_array,text_array);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; temp = J(nrow(age_array),1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i = 1 to nrow(age_array);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; age = age_array&lt;I&gt;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text = strip(text_array&lt;I&gt;);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp&lt;I&gt; = test(age, text);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return(temp);&lt;BR /&gt;finish;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;age_vect = {1,2,3,4,5};&lt;BR /&gt;text_vect = {YES, NO, NO, NO, YES};&lt;BR /&gt;r = MyApply(age_vect, text_vect);&lt;BR /&gt;print r;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2012 12:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Passing-a-vector-of-strings-as-an-argument-to-an-IML-function/m-p/125180#M954</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2012-09-20T12:52:19Z</dc:date>
    </item>
  </channel>
</rss>

