<?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: Format is applied to new contructed variable but not to existing variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932716#M366910</link>
    <description>&lt;P&gt;This sentence&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The only thing that makes sense is that the formatting is retained from the original data.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;makes no sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A FORMAT is just instructions for how to display the values.&amp;nbsp; Changing the format attached to the data cannot change the data.&amp;nbsp; &amp;nbsp;That a different format was used to display the values before would not have any impact on displaying the values now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also this step is not needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA temp.want;
  SET temp.have;
  FORMAT Any_cancer YESFMT_r. HLT_OCSTROKE YESFMT_r.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just add the FORMAT statement to the PROC step if want that step to use those formats when displaying those variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jun 2024 18:44:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-06-17T18:44:44Z</dc:date>
    <item>
      <title>Format is applied to new contructed variable but not to existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932710#M366907</link>
      <description>&lt;P&gt;I created a yes/no/missing format. It works when I apply it to a variable that I constructed in my syntax, but not to variables that were already present in the data file. Could the existing variables already have a format that is being retained? And if so, how do I override it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The syntax below will produce a freq table for Any_cancer with 1:Yes, 2: No, Inapplicable/Missing, in that order.&amp;nbsp; This is a constructed variable, and the output is being put into a table. So having it in the correct order is important.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The table for HLT_OCSTROKE shows 2, 1:Yes, Inapplicable/Missing, in that order. This is an existing variable in the data, and there are about 10 more that are doing the same thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would add sample data, but I can't see how it would fail to run properly with new data. The only thing that makes sense is that the formatting is retained from the original data.&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;LIBNAME temp "C:\SAStemp";

proc format library=temp;

value yesfmt_r
1='1:Yes'
2='2:No'
.='Inapplicable/Missing'
.R='Inapplicable/Missing'
.D='Inapplicable/Missing'
.N='Inapplicable/Missing';
RUN;

DATA temp.want; SET temp.have;
FORMAT
Any_cancer	YESFMT_r.
HLT_OCSTROKE	YESFMT_r.;
RUN;

PROC FREQ data=temp.want; TABLES Any_cancer HLT_OCSTROKE / missing; 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;</description>
      <pubDate>Mon, 17 Jun 2024 17:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932710#M366907</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2024-06-17T17:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Format is applied to new contructed variable but not to existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932715#M366909</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;The syntax below will produce a freq table for Any_cancer with 1:Yes, 2: No, Inapplicable/Missing, in that order.&amp;nbsp; This is a constructed variable, and the output is being put into a table. So having it in the correct order is important.&lt;/EM&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;The order in PROC FORMAT is irrelevant and not used. If you want the results in a particular order in the PROC FREQ output, then you need to use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_freq_syntax01.htm#statug.freq.freqorder" target="_self"&gt;ORDER= option&lt;/A&gt; in PROC FORMAT.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I think you will need to sort the data so that the categories are in the order you want them in after the sort, and then in PROC FREQ use ORDER=DATA.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Lastly, the usage of '1: Yes' instead of 'Yes' and '2: No' instead of 'No' seems un-professional to me, and unnecessary. Take the numbers out of the format, and sort the data in the right order and use ORDER=DATA.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 18:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932715#M366909</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-17T18:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Format is applied to new contructed variable but not to existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932716#M366910</link>
      <description>&lt;P&gt;This sentence&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The only thing that makes sense is that the formatting is retained from the original data.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;makes no sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A FORMAT is just instructions for how to display the values.&amp;nbsp; Changing the format attached to the data cannot change the data.&amp;nbsp; &amp;nbsp;That a different format was used to display the values before would not have any impact on displaying the values now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also this step is not needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA temp.want;
  SET temp.have;
  FORMAT Any_cancer YESFMT_r. HLT_OCSTROKE YESFMT_r.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just add the FORMAT statement to the PROC step if want that step to use those formats when displaying those variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 18:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932716#M366910</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-17T18:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Format is applied to new contructed variable but not to existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932717#M366911</link>
      <description>&lt;P&gt;This step is writing the format into the catalog named TEMP.FORMATS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=temp;
value yesfmt_r
 1='1:Yes' 
2='2:No'
.='Inapplicable/Missing'
.R='Inapplicable/Missing'
.D='Inapplicable/Missing'
.N='Inapplicable/Missing'
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is that catalog included in the list of catalogs that SAS will search when trying to find the format?&lt;/P&gt;
&lt;P&gt;And if so does TEMP.FORMATS come BEFORE any other catalogs that might have a FORMAT with the same name included in it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the value of the FMTSEARCH system option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(getoption(FMTSEARCH));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jun 2024 18:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932717#M366911</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-17T18:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Format is applied to new contructed variable but not to existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932718#M366912</link>
      <description>The code shown applies it to only new variables, can you show how you're applying it to old variables? &lt;BR /&gt;&lt;BR /&gt;And the log?</description>
      <pubDate>Mon, 17 Jun 2024 19:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932718#M366912</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-06-17T19:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Format is applied to new contructed variable but not to existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932722#M366913</link>
      <description>&lt;P&gt;Here is an example showing how to use three different formats to display the exact same values in different ways with PROC FREQ.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do x=.,.a,.n,.r,.d,1,2; 
     yn=x; ynr=x;
     output; 
  end;
run;

proc format ;
value yn 1='Yes' 2='No';
value ynr .,.n,.r,.d = 'Invalid Data' 1='Yes' 2='No';
run;

proc freq data=have;
  tables x yn ynr / missing;
  format yn yn. ynr ynr. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1718651692619.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/97533i0F61A702DCCAA63F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1718651692619.png" alt="Tom_0-1718651692619.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1718651713384.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/97534i883B8A73BD9CD732/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1718651713384.png" alt="Tom_1-1718651713384.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_2-1718651731502.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/97535i987D5D066970B09B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_2-1718651731502.png" alt="Tom_2-1718651731502.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 19:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-is-applied-to-new-contructed-variable-but-not-to-existing/m-p/932722#M366913</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-17T19:15:38Z</dc:date>
    </item>
  </channel>
</rss>

