<?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 create binned variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851694#M336650</link>
    <description>&lt;P&gt;The beauty of using PROC FORMAT is that you do not need to create a new variable that contains the bin information; you simply apply the format to an existing variable. Examples and a discussion are given in&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2019/06/10/5-reasons-to-use-proc-format-to-recode-variables-in-sas.html" target="_self"&gt;"5 reasons to use PROC FORMAT to recode variables in SAS."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the following example might suit your needs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Months @@;
RawMonts = Months;
datalines;
0 11 12 13 23 24 25 35 36 37 59 60 61 73
11.9 12.1 13.3 23.7 24.2
;

/* create a YOL format */
proc format;
value YOLFmt  
       low -  12  = "0-12 Months"    /* &amp;lt;= 12    */
       12 &amp;lt;-  24  = "13-24 months"   /* (12, 24] */
       24 &amp;lt;-  36  = "25-36 months"   /* (24, 36] */
       36 &amp;lt;-  60  = "36-60 months"  
       60 &amp;lt;- high = "61+ months";   
run;

/* apply the format */
proc print data=Have;
   format Months YOLFmt.;
run;

/* apply the format in a computational procedure */
proc freq data=Have;
   format Months YOLFmt.;
   tables Months / nocol norow nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although it is rarely necessary, you can also use the format to create a NEW variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* if necessary, you can create a new variable, but it is rarely necessary */
data Want;
set Have;
length YOL $12;
YOL = put(Months, YOLFmt.);
run;

proc print data=Want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 31 Dec 2022 12:47:43 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2022-12-31T12:47:43Z</dc:date>
    <item>
      <title>proc format variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851662#M336637</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;SPAN&gt;I'm still starting out on SAS so please bear with me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I use proc format “YOL” into the each respective years: “0-12 years”, “13-24 years”, “25-36 years”, “36-60 years” and “61 years+”&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have them saved in a dataset under the variable "YOL" (Years of Loyaltyy).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 13:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851662#M336637</guid>
      <dc:creator>lolol0101</dc:creator>
      <dc:date>2022-12-31T13:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binned variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851669#M336641</link>
      <description>&lt;P&gt;Create a format for the "age" groups. Then use it in statistic procedures for the "age" variable. The procedures will use the formatted value for the groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For detailed help, show your (intended) analysis code.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 07:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851669#M336641</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-31T07:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binned variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851689#M336646</link>
      <description>&lt;P&gt;since we don't have your data (you should really provide example data with your questions), here is an example using SASHELP.CARS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value msrpf 0-&amp;lt;10000='$0-$10K' 10000-&amp;lt;20000='$10K-$20K'
        20000-&amp;lt;30000='$20K-$30K' 30000-high='&amp;gt;=$30K';
run;

proc means data=sashelp.cars;
    var horsepower;
    class msrp;
    format msrp msrpf.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Dec 2022 10:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851689#M336646</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-31T10:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binned variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851694#M336650</link>
      <description>&lt;P&gt;The beauty of using PROC FORMAT is that you do not need to create a new variable that contains the bin information; you simply apply the format to an existing variable. Examples and a discussion are given in&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2019/06/10/5-reasons-to-use-proc-format-to-recode-variables-in-sas.html" target="_self"&gt;"5 reasons to use PROC FORMAT to recode variables in SAS."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the following example might suit your needs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Months @@;
RawMonts = Months;
datalines;
0 11 12 13 23 24 25 35 36 37 59 60 61 73
11.9 12.1 13.3 23.7 24.2
;

/* create a YOL format */
proc format;
value YOLFmt  
       low -  12  = "0-12 Months"    /* &amp;lt;= 12    */
       12 &amp;lt;-  24  = "13-24 months"   /* (12, 24] */
       24 &amp;lt;-  36  = "25-36 months"   /* (24, 36] */
       36 &amp;lt;-  60  = "36-60 months"  
       60 &amp;lt;- high = "61+ months";   
run;

/* apply the format */
proc print data=Have;
   format Months YOLFmt.;
run;

/* apply the format in a computational procedure */
proc freq data=Have;
   format Months YOLFmt.;
   tables Months / nocol norow nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although it is rarely necessary, you can also use the format to create a NEW variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* if necessary, you can create a new variable, but it is rarely necessary */
data Want;
set Have;
length YOL $12;
YOL = put(Months, YOLFmt.);
run;

proc print data=Want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Dec 2022 12:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-variable/m-p/851694#M336650</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-12-31T12:47:43Z</dc:date>
    </item>
  </channel>
</rss>

