<?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: Create a macro to change the number of decimal places for each statistic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708264#M217643</link>
    <description>&lt;P&gt;So, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351284"&gt;@Christen&lt;/a&gt; , this comment is not directed at you but at whoever insists that macros be used here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that when you are learning to use macros, you also need to learn when NOT to use macros, and so the assignment requiring you to solve the problems with macros is a poor assignment that teaches the wrong lessons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For anyone else reading along, here is a solution that doesn't use macros&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set vsstat;
    if parmcd='TEMPERATURE' then do;
        aval_mean=round(aval_mean,0.01);
        aval_stddev=round(aval_stddev,0.001);
        aval_median=round(aval_median,0.01);
        aval_min=round(aval_min,0.01);
        aval_max=round(aval_max,0.01);
    end;
    else if parmcd='BP SYSTOLIC' then do;
        /* Then you repeat the above with modifications to the ROUND function */
        /* for the other variables, but I'm lazy so I didn't do it */
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similar use of the ROUND function can be done in PROC REPORT rather than a DATA step. Or in PROC REPORT, you can use formats to control the number of decimal places.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Dec 2020 14:42:13 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-12-26T14:42:13Z</dc:date>
    <item>
      <title>Create a macro to change the number of decimal places for each statistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708212#M217592</link>
      <description>&lt;P&gt;Hello! Could you plese help me with my task? I need create a macro wich change the number of decimal.&lt;/P&gt;&lt;P&gt;Default: N 0; Mean 1; SD 2; Median 1; Min Max 1.&lt;BR /&gt;For Temperature set N 0; Mean 2; SD 3; Median 2; Min Max 2.&lt;BR /&gt;For Systolic/Diastolic BP set N 0; Mean 1; SD 1; Median 1; Min Max 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For others leave default.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I have raw data, then I apply proc means and get statistics.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data = vs n mean median std min max noprint nway;&lt;BR /&gt;var aval;&lt;BR /&gt;class paramcd;&lt;BR /&gt;output out = vsstat(drop= _TYPE_ _FREQ_) n =&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mean =&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; std =&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; median =&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; min =&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; max =&amp;nbsp; / autoname;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After proc means I need to create a macro with&amp;nbsp;the conditions that were above.&amp;nbsp;My vsstat looks like this.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dataset.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53023iFD0CA88E037BF95C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Dataset.PNG" alt="Dataset.PNG" /&gt;&lt;/span&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Dec 2020 22:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708212#M217592</guid>
      <dc:creator>Christen</dc:creator>
      <dc:date>2020-12-25T22:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to change the number of decimal places for each statistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708216#M217596</link>
      <description>&lt;P&gt;Are you thinking about using the ROUND function to limit the number of decimal places?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want this limited number of decimal places in a report? Or somewhere else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's no need to use a macro, either a data step or PROC REPORT will get you there.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Dec 2020 22:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708216#M217596</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-25T22:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to change the number of decimal places for each statistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708217#M217597</link>
      <description>I understand that I can do it without a macro, but in my task says that it must necessarily be used. I was thinking about the round function, but I don't understand how to write it correctly into a macro</description>
      <pubDate>Fri, 25 Dec 2020 23:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708217#M217597</guid>
      <dc:creator>Christen</dc:creator>
      <dc:date>2020-12-25T23:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to change the number of decimal places for each statistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708264#M217643</link>
      <description>&lt;P&gt;So, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351284"&gt;@Christen&lt;/a&gt; , this comment is not directed at you but at whoever insists that macros be used here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that when you are learning to use macros, you also need to learn when NOT to use macros, and so the assignment requiring you to solve the problems with macros is a poor assignment that teaches the wrong lessons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For anyone else reading along, here is a solution that doesn't use macros&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set vsstat;
    if parmcd='TEMPERATURE' then do;
        aval_mean=round(aval_mean,0.01);
        aval_stddev=round(aval_stddev,0.001);
        aval_median=round(aval_median,0.01);
        aval_min=round(aval_min,0.01);
        aval_max=round(aval_max,0.01);
    end;
    else if parmcd='BP SYSTOLIC' then do;
        /* Then you repeat the above with modifications to the ROUND function */
        /* for the other variables, but I'm lazy so I didn't do it */
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similar use of the ROUND function can be done in PROC REPORT rather than a DATA step. Or in PROC REPORT, you can use formats to control the number of decimal places.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 14:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708264#M217643</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-26T14:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to change the number of decimal places for each statistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708277#M217650</link>
      <description>&lt;P&gt;Is your task a homework or school assignment ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if you round a value to a certain level of decimal precision, the display of that value is dependent on the variables format.&amp;nbsp; A variables format can not be changed row by row in the default viewers such as table viewer, view table or fsview.&amp;nbsp; Likewise, in default output as such from Proc PRINT will have a variables value displaying with a fixed static format, and will not change dependent on your 'parmcd'.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if parmcd = 'whatever'
  then x = round (x, 0.1);
  else x = round (x, 0.01);

format x 12.2;
&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp;&lt;EM&gt;whatever &lt;/EM&gt;parm &lt;EM&gt;x-values &lt;/EM&gt;will always show two decimal places in the viewers as ##.d0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A Proc REPORT can create output with varying format displays by using COMPUTE blocks that utilize CALL DEFINE ('&amp;lt;varname&amp;gt;', 'FORMAT', '&amp;lt;my-conditional-format&amp;gt;')&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;PRE&gt;title; footnote;

data have;
infile cards dlm=',';
length parmcd $15;
input parmcd aval_n aval_mean aval_stddev aval_median aval_min aval_max;
format _numeric_ best12.;
datalines;
BP DIASTOLIC, 936,  70.977564103,  7.524827274,  71,  50, 107
BP SYSTOLIC , 936, 117.76709402,  10.320180454, 117,  90, 149
PULSE,        936,  71.036324786, 11.074698483,  69,  49, 110
RESPIRATION,  936,  17.879273504,  1.4215145595, 18,  12,  24
TEMPERATURE,  936,  97.752457265,  0.6521985429, 97.7,95.6,99.5
;

ods html file='report.html' style=plateau;

proc report data=have;
  columns parmcd aval_: dummy;

  define _all_ / display;
  define dummy / computed noprint;

  define aval_mean / format=12.1;

  compute dummy;
    select (parmcd);
      when ('TEMPERATURE') do;
        call define('aval_mean', 'format', '12.2');&lt;BR /&gt;      end;
      otherwise;
    end;
  endcomp;
run;

ods html close;&lt;/PRE&gt;
&lt;P&gt;Produces an output with a format applied conditionally to values&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RichardADeVenezia_0-1608998732049.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53032i82E0C7634291983E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RichardADeVenezia_0-1608998732049.png" alt="RichardADeVenezia_0-1608998732049.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a control data set and macro coding to generate the source code that is the conditional application of formats in a proc report compute block.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 16:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708277#M217650</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-12-26T16:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to change the number of decimal places for each statistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708305#M217660</link>
      <description>&lt;P&gt;Good points, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;, which I hadn't even thought of. I see you don't find the need to use macros either. &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 23:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-change-the-number-of-decimal-places-for-each/m-p/708305#M217660</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-26T23:01:44Z</dc:date>
    </item>
  </channel>
</rss>

