<?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: User-Defined Function that Does String Processing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652098#M195733</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297982"&gt;@daveconifer1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try to remove the LENGTH statement and adapt the FUNCTION definition as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function davecase(instring $) $ 80;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-&amp;gt; in the parenthesis, you specify the input variable type ($)&lt;/P&gt;
&lt;P&gt;-&amp;gt; after the parenthesis, you specify the output type and set the proper length (default = 8).&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Sun, 31 May 2020 16:37:42 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-05-31T16:37:42Z</dc:date>
    <item>
      <title>User-Defined Function that Does String Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652093#M195730</link>
      <description>&lt;P&gt;I'm trying to create a user-define function that will work on character strings, so first I decided to learn the "plumbing" before developing the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created two user defined functions: DAVECASE(simply returns the length of a character string) and DAVESUM(returns the sum of the two integers passed in).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=macros.userddefinedfunctions.davecase;  ** path/name for user-defined function **;

function davecase(instring);
 
      propstr = LENGTH(instring);

      return(propstr);

endsub;

function davesum(part1,part2);

      newsum = part1 + part2;

     return(newsum);

endsub;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code from which these two user-define functions are called:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
 
     stringx = 'this is the untouched string';

	 daveway = DAVECASE(stringx);   ** gets tripped up, seems to expect integer **;

	 oldway = PROPCASE(stringx);     ** works fine **;

	 total = DAVESUM(2,3);       ** works fine;

	 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DAVESUM works perfectly, returning 5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DAVECASE seems to get tripped up because somewhere along the line an integer is expected instead of a character string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;27         data x;
28         
29              stringx = 'this is the untouched string';
30         
31         	 daveway = DAVECASE(stringx);   ** gets tripped up, seems to expect integer **;
32         
33         	 oldway = PROPCASE(stringx);     ** works fine **;
34         
35         	 total = DAVESUM(2,3);       ** works fine;
36         
37         	 run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      31:22   
NOTE: Invalid numeric data, stringx='this is the untouched string' , at line 31 column 22.
stringx=this is the untouched string daveway=1 oldway=This Is The Untouched String total=5 _ERROR_=1 _N_=1
NOTE: The data set WORK.X has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something I need to do to indicate that the value being passed to DAVECASE is character?&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;...dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 16:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652093#M195730</guid>
      <dc:creator>daveconifer1</dc:creator>
      <dc:date>2020-05-31T16:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Function that Does String Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652094#M195731</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297982"&gt;@daveconifer1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to specify that the argument is a character one by adding a '$' as follows in the function definition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function davecase(instring $);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NB: for the second function, contrary to the SUM() function, the "+" operator does not handle missing values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 16:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652094#M195731</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-31T16:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Function that Does String Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652096#M195732</link>
      <description>&lt;P&gt;Thanks, Ed!&amp;nbsp; I was all over the documentation, or so I thought, but I didn't see that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got past that, and now my function has a new issue, so that's progress.&amp;nbsp; This isn't as straightforward as i thought.&amp;nbsp; I simplified DAVECASE to just return a copy of the argument:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function davecase(instring $);
 
      length propstr $ 80 ;

      propstr = instring;

      return(propstr);

endsub;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I still get this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;149        data x;
150        
151             stringx = 'this is the untouched string';
152        
153        	 daveway = DAVECASE(stringx);   ** gets tripped up, seems to expect integer **;
154        
The SAS System

155        	 oldway = PROPCASE(stringx);     ** works fine **;
156        
157        	 total = DAVESUM(2,3);       ** works fine;
158        
159        	 run;

ERROR: Unable to convert a character value to a numeric value in function 'davecase' in statement number 3 at line 7 column 8.
       The statement was:
    0     (7:8)      _davecase_ = Move N&amp;lt;=C(propstr="this is the untouched string                                                    
")
ERROR: Exception occurred during subroutine call.
stringx=this is the untouched string daveway= oldway=This Is The Untouched String total=5 _ERROR_=1 _N_=1
NOTE: The data set WORK.X has 1 observations and 4 variables.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll look for more documentation and examples.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...dave&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 16:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652096#M195732</guid>
      <dc:creator>daveconifer1</dc:creator>
      <dc:date>2020-05-31T16:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Function that Does String Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652098#M195733</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297982"&gt;@daveconifer1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try to remove the LENGTH statement and adapt the FUNCTION definition as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;function davecase(instring $) $ 80;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-&amp;gt; in the parenthesis, you specify the input variable type ($)&lt;/P&gt;
&lt;P&gt;-&amp;gt; after the parenthesis, you specify the output type and set the proper length (default = 8).&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 16:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652098#M195733</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-31T16:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Function that Does String Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652102#M195735</link>
      <description>&lt;P&gt;Thanks so much again, Ed!&amp;nbsp; That worked perfectly, and makes perfect sense to me as well.&amp;nbsp; I didn't like that LENGTH statement for the return argument, I was just trying stuff.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help.&amp;nbsp; Now I can work on the function, since the plumbing is working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 17:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652102#M195735</guid>
      <dc:creator>daveconifer1</dc:creator>
      <dc:date>2020-05-31T17:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Function that Does String Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652103#M195736</link>
      <description>Awesome!&lt;BR /&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297982"&gt;@daveconifer1&lt;/a&gt; &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;</description>
      <pubDate>Sun, 31 May 2020 17:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-Defined-Function-that-Does-String-Processing/m-p/652103#M195736</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-31T17:59:43Z</dc:date>
    </item>
  </channel>
</rss>

