<?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 and apply the format based on the Range of Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877783#M346766</link>
    <description>And because the underlying data is numeric should still sort correctly avoiding the need for the group4n variable. Otherwise, you need two formats, one for order and one for display. &lt;BR /&gt;&lt;BR /&gt;Formats are definitely the way to go though.</description>
    <pubDate>Fri, 26 May 2023 20:48:33 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-05-26T20:48:33Z</dc:date>
    <item>
      <title>Create and apply the format based on the Range of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877775#M346762</link>
      <description>&lt;P&gt;&amp;nbsp;I am trying to derive a variable based on the age in my dataset. Is there an easy way to&amp;nbsp; use and apply the formats with out writing "IF" and&amp;nbsp; "THEN" conditions?&lt;/P&gt;
&lt;P&gt;Thank you for your responses.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data sas;
 set sashelp.class;
 	length group4 $20.;

 	if age &amp;lt; 12 then do; 			group4= '&amp;lt;12 years';			 group4n = 1; 	end;
	else if 12=&amp;lt; age &amp;lt;13 then do;	group4= '&amp;gt;=12 to &amp;lt;14 years'; 	 group4n = 2;	end;
	else if 13=&amp;lt; age &amp;lt;14 then do; 	group4= '&amp;gt;=14 to &amp;lt;15 years'; 	 group4n = 3; 	end;
	else if age &amp;gt;= 14 	  then do;	group4= '&amp;gt;=15 years'; 			 group4n = 4;	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 May 2023 20:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877775#M346762</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-05-26T20:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create and apply the format based on the Range of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877778#M346764</link>
      <description>&lt;P&gt;Use proc format to create a custom format, then apply it in data step with PUT function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value agefmt low-12 = '&amp;lt;12 years'
				 12-13= '&amp;lt;14 years'
				 14= '&amp;lt;15 years'
				 15-high= '&amp;gt;=15 years';
run; 

data want;
	set sashelp.class;
	agegroup= put(age, agefmt.);
proc print;run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 May 2023 20:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877778#M346764</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-26T20:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create and apply the format based on the Range of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877780#M346765</link>
      <description>&lt;P&gt;Or don't bother to create a new variable at all. Using the format from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt; as an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc freq data=sashelp.class;
   tables age;
   format age agefmt. ;
run;&lt;/PRE&gt;
&lt;P&gt;The groups created by a custom format will be honored by reporting, analysis and generally for graphing purposes.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 20:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877780#M346765</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-26T20:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create and apply the format based on the Range of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877783#M346766</link>
      <description>And because the underlying data is numeric should still sort correctly avoiding the need for the group4n variable. Otherwise, you need two formats, one for order and one for display. &lt;BR /&gt;&lt;BR /&gt;Formats are definitely the way to go though.</description>
      <pubDate>Fri, 26 May 2023 20:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/877783#M346766</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-26T20:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create and apply the format based on the Range of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/878718#M347185</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 16:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/878718#M347185</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-06-01T16:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create and apply the format based on the Range of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/878726#M347186</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Use proc format to create a custom format, then apply it in data step with PUT function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value agefmt low-12 = '&amp;lt;12 years'
				 12-13= '&amp;lt;14 years'
				 14= '&amp;lt;15 years'
				 15-high= '&amp;gt;=15 years';
run; 

data want;
	set sashelp.class;
	agegroup= put(age, agefmt.);
proc print;run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, do NOT do this. Specifically this part:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	agegroup= put(age, agefmt.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a format statement to assign the agefmt. format to age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format age agefmt.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This not only is faster but it keeps the variable AGE as numeric, which also allows the age groups to sort in NUMERIC order. If you use the PUT statement, the values in AGEGROUP are text and will sort in alphabetical order, which is generally not what you want.&amp;nbsp;You don't need variable AGEGROUP at all.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 17:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-and-apply-the-format-based-on-the-Range-of-Values/m-p/878726#M347186</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-01T17:09:28Z</dc:date>
    </item>
  </channel>
</rss>

