<?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: Proc format not printing label name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918737#M41133</link>
    <description>&lt;P&gt;One way to think about FORMATS is as "Value Labels".&amp;nbsp; &amp;nbsp;Whenever you display the value of of variable (e.g. using PROC FREQ), SAS needs to decide how to display it.&amp;nbsp; With numeric values, SAS will guess a reasonable way to display the value, based on the size of the number.&amp;nbsp; But sometimes you don't want to display the number.&amp;nbsp; You want to display a label.&amp;nbsp; Maybe it's because you have have a numeric variable where 0 means "No" and 1 means "Yes", and you want to display "No" or "Yes".&amp;nbsp; Or as in your case, maybe it's because you want to display the label for a group of values, instead of the values themselves.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The format itself isn't a variable, and doesn't create a variable.&amp;nbsp; It just creates a simple look-up table where values on the left are matched to labels on the right.&amp;nbsp; Below code will create two different formats, which group age in different ways:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value age_range_group
    30 - &amp;lt;40 = '30 to 39'
    40 - &amp;lt;50 = '40 to 49'
    50 - &amp;lt;60 = '50 to 59'
    60 - &amp;lt;70 = '60 to 69'
    70 - &amp;lt;80 = '70 to 79'
    80 - &amp;lt;90 = '80 to 89'
    other = 'missing'
  ;

  value lifestage
    1 - &amp;lt;18   = 'Child'
    18- &amp;lt;65   = 'Adult'
    65- 100   = 'Senior'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the same input data (note this time I do not have a FORMAT statement in the DATA step code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input age_P1 ;
  cards ;
35.1
71.2
.
;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can run PROC FREQ, and decide whether to use the default format to display values (which will show "35.1" and "75.1") or you can use one of the custom formats you created.&amp;nbsp; So the format statement is saying "please use this format to display the values."&amp;nbsp; The format itself is just a look up table that links values to value labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have ;
  tables age_P1 ;
run ;

proc freq data=have ;
  tables age_P1 ;
  format age_P1 age_range_group. ;
run ;

proc freq data=have ;
  tables age_P1 ;
  format age_P1 lifestage. ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 03 Mar 2024 15:13:25 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2024-03-03T15:13:25Z</dc:date>
    <item>
      <title>Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918697#M41127</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set with ages ranging from 39.9 to 87.6 and want to combine these into categories (30-39, 40-49, etc.) I wrote the following code:&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value age_range_group
30 = '30 to 39'
40 = '40 to 49'
50 = '50 to 59'
60 = '60 to 69'
70 = '70 to 79'
80 = '80 to 89'
other = 'missing'; *not sure this line works?;
run;

data temp1;
set temp;
where age_P1;
if age_P1 &amp;lt;=39.9 then age_range_group = 30;
if age_P1 &amp;gt;=40 and age_P1&amp;lt;50 then age_range_group=40;
if age_P1 &amp;gt;=50 and age_P1&amp;lt;60 then age_range_group=50;
if age_P1 &amp;gt;=60 and age_P1&amp;lt;70 then age_range_group=60;
if age_P1 &amp;gt;=70 and age_P1&amp;lt;80 then age_range_group=70;
if age_P1 &amp;gt;=80 and age_P1&amp;lt;90 then age_range_group=80;
format age_P1 age_range_group.;
run;

proc freq data=temp1;
tables age_range_group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And get the following output. It does not retain my Label.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kristiepauly_0-1709411861880.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94318i162EBC6F333D0D7A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kristiepauly_0-1709411861880.png" alt="kristiepauly_0-1709411861880.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I then tried adding a Proc print data=temp1 label; (before the proc freq code above) but SAS says the file is too big and won't output.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions are greatly appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2024 20:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918697#M41127</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2024-03-02T20:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918699#M41128</link>
      <description>&lt;P&gt;Your created a variable named age_range_group, but the FORMAT statement applied your format to the variable age_P1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format age_P1 age_range_group.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format age_range_group age_range_group.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can make this easier. The format can actually do the grouping for you.&amp;nbsp; So you can make a format like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value age_range_group
    30 - &amp;lt;40 = '30 to 39'
    40 - &amp;lt;50 = '40 to 49'
    50 - &amp;lt;60 = '50 to 59'
    60 - &amp;lt;70 = '60 to 69'
    70 - &amp;lt;80 = '70 to 79'
    80 - &amp;lt;90 = '80 to 89'
    other = 'missing'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then you could use that format on your Age_P1 variable, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input age_P1 ;
  format age_P1 age_range_group. ;
  cards ;
35.1
71.2
.
;
run ;

proc freq data=have ;
  tables age_P1 /missing;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns:&lt;/P&gt;
&lt;PRE&gt;                      The FREQ Procedure

                                     Cumulative    Cumulative
  age_P1    Frequency     Percent     Frequency      Percent
missing            1       33.33             1        33.33
30 to 39           1       33.33             2        66.67
70 to 79           1       33.33             3       100.00
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2024 21:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918699#M41128</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-03-02T21:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918702#M41129</link>
      <description>&lt;P&gt;Thank you, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;.&amp;nbsp; Your code is a lot easier however, I'm curious what happens to the age_range_group variable that I created? I thought the format age_P1 age_range_group.; code is telling sas to make the variable age_P1 into the new variable age_range_group.&amp;nbsp; Not so?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than missing that new variable name, it works perfectly.&amp;nbsp; Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code/output below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value age_range_group
	30 - &amp;lt;40 = '30 to 39'
	40 - &amp;lt;50 = '40 to 49'
	50 - &amp;lt;60 = '50 to 59'
	60 - &amp;lt;70 = '60 to 69'
	70 - &amp;lt;80 = '70 to 79'
	80 - &amp;lt;90 = '80 to 89'
	other = 'missing'; 
run;

data temp1;
	set temp;
	format age_P1 age_range_group.;
	run;

proc freq data=temp1;
	tables age_P1/missing;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kristiepauly_1-1709415790498.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94320iD3D19106C606BA24/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kristiepauly_1-1709415790498.png" alt="kristiepauly_1-1709415790498.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2024 21:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918702#M41129</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2024-03-02T21:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918718#M41132</link>
      <description>&lt;P&gt;A format does not create a new variable, it only influences how the values of an existing variable are displayed, or grouped with procedures like FREQ.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2024 07:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918718#M41132</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-03T07:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918737#M41133</link>
      <description>&lt;P&gt;One way to think about FORMATS is as "Value Labels".&amp;nbsp; &amp;nbsp;Whenever you display the value of of variable (e.g. using PROC FREQ), SAS needs to decide how to display it.&amp;nbsp; With numeric values, SAS will guess a reasonable way to display the value, based on the size of the number.&amp;nbsp; But sometimes you don't want to display the number.&amp;nbsp; You want to display a label.&amp;nbsp; Maybe it's because you have have a numeric variable where 0 means "No" and 1 means "Yes", and you want to display "No" or "Yes".&amp;nbsp; Or as in your case, maybe it's because you want to display the label for a group of values, instead of the values themselves.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The format itself isn't a variable, and doesn't create a variable.&amp;nbsp; It just creates a simple look-up table where values on the left are matched to labels on the right.&amp;nbsp; Below code will create two different formats, which group age in different ways:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value age_range_group
    30 - &amp;lt;40 = '30 to 39'
    40 - &amp;lt;50 = '40 to 49'
    50 - &amp;lt;60 = '50 to 59'
    60 - &amp;lt;70 = '60 to 69'
    70 - &amp;lt;80 = '70 to 79'
    80 - &amp;lt;90 = '80 to 89'
    other = 'missing'
  ;

  value lifestage
    1 - &amp;lt;18   = 'Child'
    18- &amp;lt;65   = 'Adult'
    65- 100   = 'Senior'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the same input data (note this time I do not have a FORMAT statement in the DATA step code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input age_P1 ;
  cards ;
35.1
71.2
.
;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can run PROC FREQ, and decide whether to use the default format to display values (which will show "35.1" and "75.1") or you can use one of the custom formats you created.&amp;nbsp; So the format statement is saying "please use this format to display the values."&amp;nbsp; The format itself is just a look up table that links values to value labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have ;
  tables age_P1 ;
run ;

proc freq data=have ;
  tables age_P1 ;
  format age_P1 age_range_group. ;
run ;

proc freq data=have ;
  tables age_P1 ;
  format age_P1 lifestage. ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Mar 2024 15:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918737#M41133</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-03-03T15:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918738#M41134</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344524"&gt;@kristiepauly&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;.&amp;nbsp; Your code is a lot easier however, I'm curious what happens to the age_range_group variable that I created? I thought the format age_P1 age_range_group.; code is telling sas to make the variable age_P1 into the new variable age_range_group.&amp;nbsp; Not so?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than missing that new variable name, it works perfectly.&amp;nbsp; Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code/output below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value age_range_group
	30 - &amp;lt;40 = '30 to 39'
	40 - &amp;lt;50 = '40 to 49'
	50 - &amp;lt;60 = '50 to 59'
	60 - &amp;lt;70 = '60 to 69'
	70 - &amp;lt;80 = '70 to 79'
	80 - &amp;lt;90 = '80 to 89'
	other = 'missing'; 
run;

data temp1;
	set temp;
	format age_P1 age_range_group.;
	run;

proc freq data=temp1;
	tables age_P1/missing;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kristiepauly_1-1709415790498.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94320iD3D19106C606BA24/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kristiepauly_1-1709415790498.png" alt="kristiepauly_1-1709415790498.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you don't want the column heading to read Age_P1, you can assign a label to the variable Age_P1. In PROC FREQ add&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;label age_p1='Age at Current Visit';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;label age_p1='Age Range Group';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note when creating labels, do your audience a favor and create labels that are actual English, with proper capitalization, and not a computer programming language variable name such as &lt;FONT face="courier new,courier"&gt;age_range_group&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2024 17:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918738#M41134</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-03T17:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format not printing label name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918739#M41135</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I thought the format age_P1 age_range_group.; code is telling sas to make the variable age_P1 into the new variable age_range_group.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Formats are instructions for how to convert values into text.&amp;nbsp; The FORMAT statement just attaches a format to a variable so it will be used to display the values of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use a format to make a new variable then use a normal ASSIGNMENT statement and use the PUT() function to apply the format to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to make new variable named&amp;nbsp; age_range_group from the existing variable named&amp;nbsp; age_P1 using the format named age_range_group you would use a statement like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;age_range_group = put(age_P1,age_range_group.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;AGE_RANGE_GROUP will be a CHARACTER variable since formats always generate text from values.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2024 17:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-format-not-printing-label-name/m-p/918739#M41135</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-03T17:33:01Z</dc:date>
    </item>
  </channel>
</rss>

