<?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 to categorize a numeric number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/643715#M192158</link>
    <description>&lt;P&gt;Your format is for numeric values and your AGEN variable is character as shown by assigning values like "1".&lt;/P&gt;
&lt;P&gt;I suspect that somewhere in your log you have something similar to&lt;/P&gt;
&lt;P&gt;"Format $AgeFormat not found". To work with values like "1" "2" etc the format name must be $AgeFormat to match character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is more typical use of format&lt;/P&gt;
&lt;PRE&gt;proc format;
	value AgeFormat
 1 - 17='Adolescent' 
18 - 39='Young Adult' 
40 - 55='MiddleAge' 
56 - high ='Older Adult';
run;&lt;/PRE&gt;
&lt;P&gt;You also reference a variable AgeC that may not have been created.&lt;/P&gt;
&lt;P&gt;Use the format with the original numeric Age variable:&lt;/P&gt;
&lt;PRE&gt;PROC sgplot DATA = work.import;
  	VBAR Age/ datalabel stat=percent  fillattrs=(color=grey);
   format age ageformat.;
  	TITLE1 "Figure 7:  Relative Frequency Bar Chart of Age categories";
	xaxis label='AgeC' labelattrs=(size=12);
	yaxis label='Percentage of Victims Killed by Police' labelattrs=(size=12);
RUN;&lt;/PRE&gt;
&lt;P&gt;One of the very nice things about most formats is that you do not need to create a new variables to create groups of values and assign a nice label. Most of the analysis, reporting and graphing procedures will use the groups created (minor exception: graphing custom picture formats with date/time/datetime values)&lt;/P&gt;</description>
    <pubDate>Tue, 28 Apr 2020 20:22:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-28T20:22:16Z</dc:date>
    <item>
      <title>How to categorize a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/643713#M192157</link>
      <description>&lt;P&gt;This is my code - Unfortunately when I tried to run the new variable, it did categorize it but it did not rename them in proc format&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*Creation of a new categorical from Quantitative;&lt;BR /&gt;&lt;BR /&gt;data Work.IMPORT;&lt;BR /&gt;	set work.IMPORT;&lt;BR /&gt;&lt;BR /&gt;	if 1 &amp;lt;=age &amp;lt;=17 then&lt;BR /&gt;		AgeN="1";&lt;BR /&gt;	else if 18 &amp;lt;=age &amp;lt;=39 then&lt;BR /&gt;		AgeN="2";&lt;BR /&gt;	else if 40&amp;lt;=age &amp;lt;=55 then&lt;BR /&gt;		AgeN="3";&lt;BR /&gt;	else if age &amp;gt;=56 then&lt;BR /&gt;		AgeN="4";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;*Step 2;&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;	value AgeFormat 1='Adolescent' 2='Young Adult' 3='MiddleAge' &lt;BR /&gt;		4='Older Adult';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;*Step 3;&lt;BR /&gt;&lt;BR /&gt;data WORK.IMPORT;&lt;BR /&gt;	set WORK.IMPORT;&lt;BR /&gt;	format AgeN AgeFormat.;&lt;BR /&gt;run;&lt;BR /&gt;proc freq data=Work.import;&lt;BR /&gt;	title "Table 5 :Frequency Table of New Categorical AgeC";&lt;BR /&gt;	tables AgeN;&lt;BR /&gt;run;&lt;BR /&gt;*Bar Chart of New Categorical Variable AgeC;&lt;BR /&gt;PROC sgplot DATA = work.import;&lt;BR /&gt;  	VBAR AgeC/ datalabel stat=percent  fillattrs=(color=grey);&lt;BR /&gt;  	TITLE1 "Figure 7:  Relative Frequency Bar Chart of New Categorical AgeC";&lt;BR /&gt;	xaxis label='AgeC' labelattrs=(size=12);&lt;BR /&gt;	yaxis label='Percentage of Victims Killed by Police' labelattrs=(size=12);&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 20:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/643713#M192157</guid>
      <dc:creator>Lexclarke11</dc:creator>
      <dc:date>2020-04-28T20:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to categorize a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/643715#M192158</link>
      <description>&lt;P&gt;Your format is for numeric values and your AGEN variable is character as shown by assigning values like "1".&lt;/P&gt;
&lt;P&gt;I suspect that somewhere in your log you have something similar to&lt;/P&gt;
&lt;P&gt;"Format $AgeFormat not found". To work with values like "1" "2" etc the format name must be $AgeFormat to match character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is more typical use of format&lt;/P&gt;
&lt;PRE&gt;proc format;
	value AgeFormat
 1 - 17='Adolescent' 
18 - 39='Young Adult' 
40 - 55='MiddleAge' 
56 - high ='Older Adult';
run;&lt;/PRE&gt;
&lt;P&gt;You also reference a variable AgeC that may not have been created.&lt;/P&gt;
&lt;P&gt;Use the format with the original numeric Age variable:&lt;/P&gt;
&lt;PRE&gt;PROC sgplot DATA = work.import;
  	VBAR Age/ datalabel stat=percent  fillattrs=(color=grey);
   format age ageformat.;
  	TITLE1 "Figure 7:  Relative Frequency Bar Chart of Age categories";
	xaxis label='AgeC' labelattrs=(size=12);
	yaxis label='Percentage of Victims Killed by Police' labelattrs=(size=12);
RUN;&lt;/PRE&gt;
&lt;P&gt;One of the very nice things about most formats is that you do not need to create a new variables to create groups of values and assign a nice label. Most of the analysis, reporting and graphing procedures will use the groups created (minor exception: graphing custom picture formats with date/time/datetime values)&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 20:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/643715#M192158</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-28T20:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to categorize a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/734279#M228765</link>
      <description>&lt;PRE&gt;data WORK.IMPORT;&lt;BR /&gt;	set WORK.IMPORT;&lt;BR /&gt;	format AgeN $AgeFormat.;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hello, You need to put&amp;nbsp; "$" before the format name as I wrote it above.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 13:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/734279#M228765</guid>
      <dc:creator>jokos</dc:creator>
      <dc:date>2021-04-15T13:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to categorize a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/734338#M228777</link>
      <description>&lt;P&gt;Remove double quotes in your first data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Work.IMPORT;
	set work.IMPORT;

	if 1 &amp;lt;=age &amp;lt;=17 then
		AgeN=1;
	else if 18 &amp;lt;=age &amp;lt;=39 then
		AgeN=2;
	else if 40&amp;lt;=age &amp;lt;=55 then
		AgeN=3;
	else if age &amp;gt;=56 then
		AgeN=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because your format is defined for numeric variables. With the " " you create character variables.&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 16:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-categorize-a-numeric-number/m-p/734338#M228777</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-04-15T16:38:17Z</dc:date>
    </item>
  </channel>
</rss>

