<?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: Self-defined function not found in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848014#M36988</link>
    <description>&lt;P&gt;Save the code, restart the session and run the code in a clean session.&lt;/P&gt;
&lt;P&gt;The errors about statements not shown, i.e. Filename, is problematic since it would be very session dependent.&lt;/P&gt;
&lt;P&gt;Code not completing may be an issue of how you submit it, if submitting "highlighted lines" or similar, or maybe having code in a comment that is not properly ended. Use of macro characters &amp;amp; or % somewhere may also be problematic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, while learning SAS it is generally not a good idea to use the same data set as source (set statement) and output (data statement) as data steps completely replace a data set when using that structure. So a minor logic error may mean having to go back (some times many) step to recover data that has been removed or modified.&lt;/P&gt;
&lt;P&gt;So instead of&lt;/P&gt;
&lt;PRE&gt;data work.cars1;
   set work.cars1;
&amp;lt;other code&amp;gt;&lt;/PRE&gt;
&lt;P&gt;It is better to use&lt;/P&gt;
&lt;PRE&gt;data work.cars2;
   set work.cars1;
&amp;lt;other code&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;Your example isn't too complicated but it can be a real bear to find out "where did that value come from" sometimes when you have replaced the source set.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Dec 2022 00:28:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-12-06T00:28:05Z</dc:date>
    <item>
      <title>Self-defined function not found</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/847996#M36985</link>
      <description>&lt;P&gt;Hi, I am learning SAS in online SAS studio as a R user following "sas-programming-for-r-users". I got the problem to use self-defined function in the exercise of the book: P69&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;data work.cars1;&lt;BR /&gt;set sashelp.cars;&lt;BR /&gt;mpg_average = mean(mpg_city,mpg_highway);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc fcmp outlib=work.functions.newfuncs;&lt;BR /&gt;function Tier(mpg_average) $;&lt;BR /&gt;length mpg_quality2 $ 8;&lt;BR /&gt;if mpg_average &amp;lt; 20 then mpg_quality2 = 'Low';&lt;BR /&gt;else if mpg_average &amp;lt;30 then mpg_quality2 = 'Median';&lt;BR /&gt;else mpg_quality2 = 'High';&lt;BR /&gt;return(mpg_quality2);&lt;BR /&gt;endsub;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options cmplib=work.functions;&lt;/P&gt;&lt;P&gt;data work.cars1;&lt;BR /&gt;set work.cars1;&lt;BR /&gt;length mpg_quality2 $ 8;&lt;BR /&gt;mpg_quality2 = Tier(mpg_average);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=work.cars1 (firstobs=65 obs=70);&lt;BR /&gt;var mpg_average mpg_quality mpg_quality2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;I could not add variable mpg_quality2 since&lt;/P&gt;&lt;P&gt;"E&lt;SPAN&gt;RROR 68-185: The function TIER is unknown, or cannot be accessed."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why proc fcmp does not work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 22:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/847996#M36985</guid>
      <dc:creator>Fisheryxy</dc:creator>
      <dc:date>2022-12-05T22:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Self-defined function not found</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848009#M36986</link>
      <description>&lt;P&gt;You would have to show the LOG for your FCMP code to see why it may not work. Does your log show text similar to this after Proc FCMP ?&lt;/P&gt;
&lt;PRE&gt;NOTE: Function Tier saved to work.functions.newfuncs.
NOTE: PROCEDURE FCMP used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I use your function with a small data set compiled locally it runs okay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did see a character between the end of Proc FCMP and the Options statement that SAS didn't like so check your log. If there are more that made it into your code that could be an issue. Also, it is a good idea to paste code or log text into a text box opened on the forum with the &amp;lt;/&amp;gt; that appears above the message window. The main message windows on the forum will reformat text, especially white space characters, and may result in code that doesn't run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What your function is doing is more typically done with a custom FORMAT in SAS than a function. Formats are look ups but restricted to single variable/ value&lt;/P&gt;
&lt;PRE&gt;Proc format;
value mpg_tier
low - &amp;lt;20 = 'Low'
20 - &amp;lt; 30 = 'Median'
30 - High = 'High'
;
run;

/* use without creating new variable*/
Proc print data=work.cars1;
   var mpg_average;
   format mpg_average mpg_tier. ;
run;
/* or create a new variable with PUT function and the format*/
data work.cars2;
   set work.cars1;
   mpg_quality2 = put(mpg_average, mpg_tier.);
run;&lt;/PRE&gt;
&lt;P&gt;There are very limited transforms that could be done with Format code. A function would be more appropriate for something using 2 or more variables or a more complex calculation or changing calculation based on range of values.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 23:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848009#M36986</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-05T23:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Self-defined function not found</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848012#M36987</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;My log file is actually problematic:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV class=""&gt;NOTE: PROCEDURE FCMP used (Total process time):&lt;/DIV&gt;&lt;DIV class=""&gt;real time 2:30.68&lt;/DIV&gt;&lt;DIV class=""&gt;user cpu time 0.04 seconds&lt;/DIV&gt;&lt;DIV class=""&gt;system cpu time 0.02 seconds&lt;/DIV&gt;&lt;DIV class=""&gt;memory 5713.87k&lt;/DIV&gt;&lt;DIV class=""&gt;OS Memory 29608.00k&lt;/DIV&gt;&lt;DIV class=""&gt;Timestamp 12/05/2022 11:54:36 PM&lt;/DIV&gt;&lt;DIV class=""&gt;Step Count 25 Switch Count 5&lt;/DIV&gt;&lt;DIV class=""&gt;Page Faults 0&lt;/DIV&gt;&lt;DIV class=""&gt;Page Reclaims 651&lt;/DIV&gt;&lt;DIV class=""&gt;Page Swaps 0&lt;/DIV&gt;&lt;DIV class=""&gt;Voluntary Context Switches 1407&lt;/DIV&gt;&lt;DIV class=""&gt;Involuntary Context Switches 0&lt;/DIV&gt;&lt;DIV class=""&gt;Block Input Operations 0&lt;/DIV&gt;&lt;DIV class=""&gt;Block Output Operations 8&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR: At least one file associated with fileref _HTMLOUT is still in use.&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR: Error in the FILENAME statement.&lt;/DIV&gt;&lt;DIV class=""&gt;68&lt;/DIV&gt;&lt;DIV class=""&gt;69 data work.cars1;&lt;/DIV&gt;&lt;DIV class=""&gt;70 set sashelp.cars;&lt;/DIV&gt;&lt;DIV class=""&gt;71 mpg_average = mean(mpg_city,mpg_highway);&lt;/DIV&gt;&lt;DIV class=""&gt;72 run;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;NOTE: There were 428 observations read from the data set SASHELP.CARS.&lt;/DIV&gt;&lt;DIV class=""&gt;NOTE: The data set WORK.CARS1 has 428 observations and 16 variables.&lt;/DIV&gt;&lt;DIV class=""&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;DIV class=""&gt;real time 0.00 seconds&lt;/DIV&gt;&lt;DIV class=""&gt;user cpu time 0.00 seconds&lt;/DIV&gt;&lt;DIV class=""&gt;system cpu time 0.00 seconds&lt;/DIV&gt;&lt;DIV class=""&gt;memory 836.90k&lt;/DIV&gt;&lt;DIV class=""&gt;OS Memory 24996.00k&lt;/DIV&gt;&lt;DIV class=""&gt;Timestamp 12/05/2022 11:54:36 PM&lt;/DIV&gt;&lt;DIV class=""&gt;Step Count 30 Switch Count 2&lt;/DIV&gt;&lt;DIV class=""&gt;Page Faults 0&lt;/DIV&gt;&lt;DIV class=""&gt;Page Reclaims 109&lt;/DIV&gt;&lt;DIV class=""&gt;Page Swaps 0&lt;/DIV&gt;&lt;DIV class=""&gt;Voluntary Context Switches 9&lt;/DIV&gt;&lt;DIV class=""&gt;Involuntary Context Switches 0&lt;/DIV&gt;&lt;DIV class=""&gt;Block Input Operations 0&lt;/DIV&gt;&lt;DIV class=""&gt;Block Output Operations 264&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;73&lt;/DIV&gt;&lt;DIV class=""&gt;74 proc fcmp outlib=work.functions.newfuncs;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;DIV class=""&gt;I got two errors upfront when I rerun the code. It seems that SAS stopped running my definition for some reasons unknown to me.&amp;nbsp;&lt;PRE&gt;&lt;CODE class=""&gt;proc fcmp outlib=work.functions.newfuncs;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 06 Dec 2022 00:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848012#M36987</guid>
      <dc:creator>Fisheryxy</dc:creator>
      <dc:date>2022-12-06T00:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Self-defined function not found</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848014#M36988</link>
      <description>&lt;P&gt;Save the code, restart the session and run the code in a clean session.&lt;/P&gt;
&lt;P&gt;The errors about statements not shown, i.e. Filename, is problematic since it would be very session dependent.&lt;/P&gt;
&lt;P&gt;Code not completing may be an issue of how you submit it, if submitting "highlighted lines" or similar, or maybe having code in a comment that is not properly ended. Use of macro characters &amp;amp; or % somewhere may also be problematic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, while learning SAS it is generally not a good idea to use the same data set as source (set statement) and output (data statement) as data steps completely replace a data set when using that structure. So a minor logic error may mean having to go back (some times many) step to recover data that has been removed or modified.&lt;/P&gt;
&lt;P&gt;So instead of&lt;/P&gt;
&lt;PRE&gt;data work.cars1;
   set work.cars1;
&amp;lt;other code&amp;gt;&lt;/PRE&gt;
&lt;P&gt;It is better to use&lt;/P&gt;
&lt;PRE&gt;data work.cars2;
   set work.cars1;
&amp;lt;other code&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;Your example isn't too complicated but it can be a real bear to find out "where did that value come from" sometimes when you have replaced the source set.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 00:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Self-defined-function-not-found/m-p/848014#M36988</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-06T00:28:05Z</dc:date>
    </item>
  </channel>
</rss>

