<?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: How do I include a format name as an argument in a function defined with PROC FCMP? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692212#M210817</link>
    <description>&lt;P&gt;option 1) replace order, first make format then function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**Define and store function ;
options dlcreatedir;
libname test "%sysfunc(pathname(work))/test" ;

**Define the format I want to use. This must be called __ESTF ;
proc format ;
    picture __Estf (round) 
        low   -  -1.1  ="00000000000009.9" (prefix = '-') 
        -1.1 &amp;lt;-&amp;lt;  0    = "9.99" (prefix = '-') 
        0     -&amp;lt;  1.1  ="9.99" 
        1.1   -   high = "00000000000009.9" ;
run ;

proc fcmp outlib=test.MyFunctions.Reporting ;
    **x (y, z) ;
    function XparenthesisYZ(__x, __y, __z) $ ;
    length __b $50 ;
    __b=compress(put(__x, __estf.))||" ("||
              compress(put(__y, __estf.))||", "||
              compress(put(__z, __estf.))||")" ;
    return (__b) ;
    endsub ;
run ;

**Apply function to test data ;
options cmplib=test.MyFunctions ;

data test ;
    input OR OR_LCL OR_UCL ;
    OR_CI = XparenthesisYZ(or, or_lcl, or_ucl) ;
    datalines ;
2.3 1.3 3.3
0.856 0.555 2.55
0.057 0.864 3.444
     ;
run ;

title "Output" ;
proc print data=test noobs ;
run ;
title ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;option 2) try function putn() which accepts format name as a string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;all the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Fri, 16 Oct 2020 19:01:34 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-10-16T19:01:34Z</dc:date>
    <item>
      <title>How do I include a format name as an argument in a function defined with PROC FCMP?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692209#M210816</link>
      <description>&lt;P&gt;I'm fairly new to PROC FCMP and am wondering if it possible to provide a format name as an argument in a function defined using PROC FCMP.&amp;nbsp;For example, in the below function to store values as `estimate (LCL, UCL)` I would like to allow&amp;nbsp;the user to specify a format name of choice without having the restriction to only accepting a user defined format named __ESTF. Ideally I would have a function&amp;nbsp;&lt;CODE class=" language-sas"&gt;XparenthesisYZ(__x, __y, __z, __fmt)&amp;nbsp;&lt;/CODE&gt;where __fmt is a format name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use SAS 9.4M5 in a Linux environment and have tried various things without any luck. Appreciate any guidance.&lt;BR /&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**Define and store function ;
libname test "C:\FCMP_Test" ;

proc fcmp outlib=test.MyFunctions.Reporting ;
    **x (y, z) ;
    function XparenthesisYZ(__x, __y, __z) $ ;
    length __b $50 ;
    __b=compress(put(__x, __estf.))||" ("||
              compress(put(__y, __estf.))||", "||
              compress(put(__z, __estf.))||")" ;
    return (__b) ;
    endsub ;
run ;

**Define the format I want to use. This must be called __ESTF ;
proc format ;
    picture __Estf (round) 
        low   -  -1.1  ="00000000000009.9" (prefix = '-') 
        -1.1 &amp;lt;-&amp;lt;  0    = "9.99" (prefix = '-') 
        0     -&amp;lt;  1.1  ="9.99" 
        1.1   -   high = "00000000000009.9" ;
run ;

**Apply function to test data ;
options cmplib=test.MyFunctions ;

data test ;
    input OR OR_LCL OR_UCL ;
    OR_CI = XparenthesisYZ(or, or_lcl, or_ucl) ;
    datalines ;
2.3 1.3 3.3
0.856 0.555 2.55
0.057 0.864 3.444
     ;
run ;

title "Output" ;
proc print data=test noobs ;
run ;
title ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 18:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692209#M210816</guid>
      <dc:creator>lopezr</dc:creator>
      <dc:date>2020-10-16T18:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I include a format name as an argument in a function defined with PROC FCMP?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692212#M210817</link>
      <description>&lt;P&gt;option 1) replace order, first make format then function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**Define and store function ;
options dlcreatedir;
libname test "%sysfunc(pathname(work))/test" ;

**Define the format I want to use. This must be called __ESTF ;
proc format ;
    picture __Estf (round) 
        low   -  -1.1  ="00000000000009.9" (prefix = '-') 
        -1.1 &amp;lt;-&amp;lt;  0    = "9.99" (prefix = '-') 
        0     -&amp;lt;  1.1  ="9.99" 
        1.1   -   high = "00000000000009.9" ;
run ;

proc fcmp outlib=test.MyFunctions.Reporting ;
    **x (y, z) ;
    function XparenthesisYZ(__x, __y, __z) $ ;
    length __b $50 ;
    __b=compress(put(__x, __estf.))||" ("||
              compress(put(__y, __estf.))||", "||
              compress(put(__z, __estf.))||")" ;
    return (__b) ;
    endsub ;
run ;

**Apply function to test data ;
options cmplib=test.MyFunctions ;

data test ;
    input OR OR_LCL OR_UCL ;
    OR_CI = XparenthesisYZ(or, or_lcl, or_ucl) ;
    datalines ;
2.3 1.3 3.3
0.856 0.555 2.55
0.057 0.864 3.444
     ;
run ;

title "Output" ;
proc print data=test noobs ;
run ;
title ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;option 2) try function putn() which accepts format name as a string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;all the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 19:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692212#M210817</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-10-16T19:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I include a format name as an argument in a function defined with PROC FCMP?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692217#M210820</link>
      <description>&lt;P&gt;To pass a format to a function pass it as a character value. Then use it with the PUTN() or PUTC() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=WORK.MyFunctions.Reporting ;
  function XparenthesisYZ(est,ll,ul,fmt $) $ ;
    length result $50 ;
    result=catx(' ('
          ,putn(est,fmt)
          ,catx(', ',putn(ll,fmt),putn(ul,fmt))
          )||')'
    ;
    return (result) ;
  endsub ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So let's test it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
    input OR OR_LCL OR_UCL ;
    OR_CI = XparenthesisYZ(or, or_lcl, or_ucl,'__estf.') ;
    OR_CI2 = XparenthesisYZ(or, or_lcl, or_ucl,'z5.2') ;

datalines ;
2.3 -1.3 3.3
0.856 0.555 2.55
0.057 0.864 3.444
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;  OR     OR_LCL    OR_UCL         OR_CI                 OR_CI2

2.300    -1.300     3.300    2.3 (-1.3, 3.3)     02.30 (-1.30, 03.30)
0.856     0.555     2.550    0.86 (0.56, 2.6)    00.86 (00.56, 02.55)
0.057     0.864     3.444    0.06 (0.86, 3.4)    00.06 (00.86, 03.44)&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Oct 2020 19:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692217#M210820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-16T19:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I include a format name as an argument in a function defined with PROC FCMP?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692226#M210827</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; ! This is exactly what I wanted.</description>
      <pubDate>Fri, 16 Oct 2020 20:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-include-a-format-name-as-an-argument-in-a-function/m-p/692226#M210827</guid>
      <dc:creator>lopezr</dc:creator>
      <dc:date>2020-10-16T20:28:21Z</dc:date>
    </item>
  </channel>
</rss>

