<?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 Debugging a function format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640863#M190964</link>
    <description>&lt;P&gt;The FORMAT Procedure docs for &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=n1eyyzaux0ze5ln1k03gl338avbj.htm&amp;amp;locale=en" target="_self"&gt;"Using a Function to Format Values"&lt;/A&gt; show an example of a function that computes the formatted values for a custom format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is that when the function contains a PUT statement, nothing appears in the Log window.&amp;nbsp; Where do the puts end up ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ods html file='quirky.html';

proc fcmp outlib=work.functions.smd;
   function qfmt(date) $;
      put date;  /************* DOES NOT GET LOGGED **************/
      return ("foobar");
/*      length qnum $4;*/
/*      qnum=put(date,yyq4.);*/
/*      if substr(qnum,3,1)='Q'*/
/*         then return(substr(qnum,3,2));*/
/*      else return(qnum);*/
   endsub;
run;

/* Make the function available to SAS. */
options cmplib=(work.functions);

/* Create a format using the function created by the FCMP procedure. */
proc format; value qfmt other=[qfmt()]; run;

/* Use the format in a SAS program.  */
data djia2009;
input closeDate date7. close;
datalines;
01jan09 800.86
02feb09 7062.93
02mar09 7608.92
01apr09 8168.12
01may09 8500.33
01jun09 8447.00
01jul09 9171.61
03aug09 9496.28
01sep09 9712.28
01oct09 9712.73
02nov09 10344.84
02dec09 10428.05
;

proc print data=djia2009;
format closedate qfmt. close dollar9.;
run;

ods html close;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;6132  ;
6133
6134  proc print data=djia2009;
6135  format closedate qfmt. close dollar9.;
6136  run;

NOTE: There were 12 observations read from the data set WORK.DJIA2009.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.06 seconds
      cpu time            0.03 seconds


6137
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="foobar.png" style="width: 175px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38402i923C5F7A8FC82584/image-size/large?v=v2&amp;amp;px=999" role="button" title="foobar.png" alt="foobar.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Apr 2020 21:43:41 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-04-17T21:43:41Z</dc:date>
    <item>
      <title>Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640863#M190964</link>
      <description>&lt;P&gt;The FORMAT Procedure docs for &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=n1eyyzaux0ze5ln1k03gl338avbj.htm&amp;amp;locale=en" target="_self"&gt;"Using a Function to Format Values"&lt;/A&gt; show an example of a function that computes the formatted values for a custom format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is that when the function contains a PUT statement, nothing appears in the Log window.&amp;nbsp; Where do the puts end up ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ods html file='quirky.html';

proc fcmp outlib=work.functions.smd;
   function qfmt(date) $;
      put date;  /************* DOES NOT GET LOGGED **************/
      return ("foobar");
/*      length qnum $4;*/
/*      qnum=put(date,yyq4.);*/
/*      if substr(qnum,3,1)='Q'*/
/*         then return(substr(qnum,3,2));*/
/*      else return(qnum);*/
   endsub;
run;

/* Make the function available to SAS. */
options cmplib=(work.functions);

/* Create a format using the function created by the FCMP procedure. */
proc format; value qfmt other=[qfmt()]; run;

/* Use the format in a SAS program.  */
data djia2009;
input closeDate date7. close;
datalines;
01jan09 800.86
02feb09 7062.93
02mar09 7608.92
01apr09 8168.12
01may09 8500.33
01jun09 8447.00
01jul09 9171.61
03aug09 9496.28
01sep09 9712.28
01oct09 9712.73
02nov09 10344.84
02dec09 10428.05
;

proc print data=djia2009;
format closedate qfmt. close dollar9.;
run;

ods html close;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;6132  ;
6133
6134  proc print data=djia2009;
6135  format closedate qfmt. close dollar9.;
6136  run;

NOTE: There were 12 observations read from the data set WORK.DJIA2009.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.06 seconds
      cpu time            0.03 seconds


6137
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="foobar.png" style="width: 175px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38402i923C5F7A8FC82584/image-size/large?v=v2&amp;amp;px=999" role="button" title="foobar.png" alt="foobar.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 21:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640863#M190964</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-17T21:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640868#M190965</link>
      <description>&lt;P&gt;If you are attempting to test this in the Proc print then create a second variable with the raw date value and use a more typcial format for display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For debugging in the data step&lt;/P&gt;
&lt;PRE&gt;data djia2009;
input closeDate date7. close;
put "Date7 format" +1 closedate= date7. +1 "Custom format" +1 closedate= qfmt.;
datalines;
01jan09 800.86
02feb09 7062.93
02mar09 7608.92
01apr09 8168.12
01may09 8500.33
;&lt;/PRE&gt;
&lt;P&gt;Tis the nature of functions that they return values, not create print style output.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 21:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640868#M190965</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-17T21:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640870#M190966</link>
      <description>&lt;P&gt;My guess is since Proc FCMP&amp;nbsp;&lt;SPAN&gt;uses the SAS language compiler to create user-defined functions. The compiler subsystem generates machine language code for the computer on which SAS is running. This guess leads me to put my bet of something akin to stored compiled macro. Plus the fact FCMP offers interaction with macro language&amp;nbsp;by using the macro function %SYSFUNC and the macro statement %SYSCALL could have made the design overriding&amp;nbsp; execution of PUT as null?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PS I am all ears to sit corrected and learn the proper mechanism besides the fun guess&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 22:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640870#M190966</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-17T22:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640878#M190967</link>
      <description>&lt;P&gt;Didn't you try it?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  y=qfmt(1111);
  z=put(2222,qfmt.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It wrote it to the listing output when I tried it.&lt;/P&gt;
&lt;PRE&gt;2366  filename list2 temp;
2367  filename log2 temp;
2368  options nosource nonotes;
2376  data _null_;
2377  put 'listing';
2378  do until(eof1);
2379    infile list2 end=eof1;
2380    input;
2381    put _infile_;
2382  end;
2383  put 'log';
2384  do until(eof2);
2385    infile log2 end=eof2;
2386    input;
2387    put _infile_;
2388  end;
2389  stop;
2390  run;

NOTE: The infile LIST2 is:
      Filename=C:\Users\ABERNA~1\AppData\Local\Temp\1\SAS Temporary Files\_TD13900_AMRL20L6F1E4992_\#LN00747,
      RECFM=V,LRECL=32767,File Size (bytes)=136,
      Last Modified=17Apr2020:18:29:06,
      Create Time=17Apr2020:18:29:06

NOTE: The infile LOG2 is:
      Filename=C:\Users\ABERNA~1\AppData\Local\Temp\1\SAS Temporary Files\_TD13900_AMRL20L6F1E4992_\#LN00748,
      RECFM=V,LRECL=32767,File Size (bytes)=6,
      Last Modified=17Apr2020:18:29:06,
      Create Time=17Apr2020:18:29:06

listing
                                                                                            16:21 Thursday, April 16, 2020  99

2222
log
1111
NOTE: 3 records were read from the infile LIST2.
      The minimum record length was 0.
      The maximum record length was 126.
NOTE: 1 record was read from the infile LOG2.
      The minimum record length was 4.
      The maximum record length was 4.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds&lt;BR /&gt;&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;Apparently PROC PRINT calls it many times per observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=sashelp.class(obs=1);
  format age qfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;                                                                                            16:21 Thursday, April 16, 2020 104

Obs     Name     Sex     Age      Height    Weight

  1    Alfred     M     foobar      69       112.5
&amp;#12;
                                                                                            16:21 Thursday, April 16, 2020 105

14
14
14
14
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 22:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640878#M190967</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-17T22:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640898#M190976</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;. Good catch. I hadn't thought to look in the OUTPUT window, and there it was. Peculiar, because ODS LISTING was closed. I am using the PUT in the function as a way to observe what a PROC is doing in concert with ODS when a styling setting to apply is obtained via .... &lt;EM&gt;style-attr=format.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 13:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/640898#M190976</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-18T13:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/641038#M191018</link>
      <description>&lt;P&gt;You guys are cleverer than me it seems.&lt;/P&gt;
&lt;P&gt;I can't get that result. Using SAS UE, the RESULTS tab remains stubbornly empty (except for the proc print output if I add that).&lt;/P&gt;
&lt;P&gt;What's the missing link? See my attempt below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.functions.smd;
   function qfmt(date) $;
      put '=&amp;gt;' date;  /************* DOES NOT GET LOGGED **************/
      return ("foobar");
/*      length qnum $4;*/
/*      qnum=put(date,yyq4.);*/
/*      if substr(qnum,3,1)='Q'*/
/*         then return(substr(qnum,3,2));*/
/*      else return(qnum);*/
   endsub;
run;

/* Make the function available to SAS. */
options cmplib=(work.functions);

/* Create a format using the function created by the FCMP procedure. */
proc format; value qfmt other=[qfmt()]; run;


/****** WHAT AM I DOING WRONG HERE? START ********/

filename list2 temp;
filename log2 temp;

ods listing;

data test;
  y=qfmt(1111);
  z=put(2222,qfmt.);
run;

proc print data=sashelp.class(obs=1);
  format age qfmt.;
run;

ods listing close;

/****** WHAT AM I DOING WRONG HERE? END ********/


data _null_;
  put 'listing';
  do until(eof1);
    infile list2 end=eof1;
    input;
    put _infile_;
  end;
  put 'log';
  do until(eof2);
    infile log2 end=eof2;
    input;
    put _infile_;
  end;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 03:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/641038#M191018</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-19T03:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/641085#M191049</link>
      <description>&lt;P&gt;You left out the PROC PRINTTO step to redirect the PRINT destination to your temporary file.&lt;/P&gt;
&lt;P&gt;Not sure where UE points the default print output.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/641085#M191049</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T13:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a function format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/642133#M191533</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;This indeed works. Any idea why the redirected (printto) output is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;=&amp;gt; 2222
&amp;#12;Obs    Name     Sex     Age      Height    Weight

  1    Joyce     F     foobar     51.3      50.5 
=&amp;gt; 11
=&amp;gt; 11
=&amp;gt; 11
=&amp;gt; 11&lt;/PRE&gt;
&lt;P&gt;but the non-redirected output (in the listing window) is:&lt;/P&gt;
&lt;PRE&gt;=&amp;gt; 2222
Obs    Name     Sex     Age      Height    Weight

=&amp;gt; 11
  1    Joyce     F     foobar     51.3      50.5 
=&amp;gt; 11

=&amp;gt; 11
&lt;/PRE&gt;
&lt;P&gt;Why should they be any different?&lt;/P&gt;
&lt;P&gt;Interesting how proc print calls the format several times per obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 00:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Debugging-a-function-format/m-p/642133#M191533</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-23T00:20:11Z</dc:date>
    </item>
  </channel>
</rss>

