<?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 Length of a variable created by a PROC FCMP character function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543115#M150124</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use for instance the SUBSTR function to create a new variable, the length of that new variable is equal to the length of the variable you use as an argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a character function with PROC FCMP and I'd like my function to have the same property.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If my function statement is like this :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function extrait(chaine $,dlm $,pos) $ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The length of the variable created when I use this function is 33 (BTW, why?). I can give an arbitrary large value for the length of the created variables (say 500...) but this would be a waste of resources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like that length to be equal to the length of the variable I'll use as the "chaine" argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is this possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sébastien&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2019 12:15:23 GMT</pubDate>
    <dc:creator>SR_FR</dc:creator>
    <dc:date>2019-03-14T12:15:23Z</dc:date>
    <item>
      <title>Length of a variable created by a PROC FCMP character function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543115#M150124</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use for instance the SUBSTR function to create a new variable, the length of that new variable is equal to the length of the variable you use as an argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a character function with PROC FCMP and I'd like my function to have the same property.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If my function statement is like this :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function extrait(chaine $,dlm $,pos) $ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The length of the variable created when I use this function is 33 (BTW, why?). I can give an arbitrary large value for the length of the created variables (say 500...) but this would be a waste of resources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like that length to be equal to the length of the variable I'll use as the "chaine" argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is this possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sébastien&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 12:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543115#M150124</guid>
      <dc:creator>SR_FR</dc:creator>
      <dc:date>2019-03-14T12:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Length of a variable created by a PROC FCMP character function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543247#M150160</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15364"&gt;@SR_FR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use for instance the SUBSTR function to create a new variable, the length of that new variable is equal to the length of the variable you use as an argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a character function with PROC FCMP and I'd like my function to have the same property.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If my function statement is like this :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function extrait(chaine $,dlm $,pos) $ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The length of the variable created when I use this function is 33 (BTW, why?). I can give an arbitrary large value for the length of the created variables (say 500...) but this would be a waste of resources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like that length to be equal to the length of the variable I'll use as the "chaine" argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is this possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sébastien&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Likely the reason your test variable has length of 33 is the first returned value had that length. The basic rule for non-defined lengths of character variables is the first use will set the length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest I could see if you don't want to be bothered to assign an explicit length to a "new" variable is to do something such as call to substr or similar function prior to the function call:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dummy = substr(var,1);&lt;/P&gt;
&lt;P&gt;dummy = extrait(var, ',',3) ; (or however you want to call your function.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 16:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543247#M150160</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-14T16:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Length of a variable created by a PROC FCMP character function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543438#M150222</link>
      <description>&lt;P&gt;the solution your propose does the job !&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;about the 33, well, it's still a mystery...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first returned value can not help to understand this length since the length of a character variable is decided during the compilation of the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;may be the complete program would help to solve the mystery...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=sasuser.funcs.temp;
   function extrait(chaine $,dlm $,pos) $ ;
   temp=0;
      do i=1 to pos;
         temp=find(chaine,dlm,temp+1);
      end;
   return(substr(chaine,1,temp-1));
   endsub;
run;

options cmplib=sasuser.funcs;

data toto;
   x="azz,bs,cezz,dd,e";
   y=3;
   dlm=',';
   gogo=extrait(x,dlm,y);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sébastien&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 08:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-a-variable-created-by-a-PROC-FCMP-character-function/m-p/543438#M150222</guid>
      <dc:creator>SR_FR</dc:creator>
      <dc:date>2019-03-15T08:35:49Z</dc:date>
    </item>
  </channel>
</rss>

