<?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 I want to categorize the age group and I am using the Data step. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849626#M37138</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am trying to categorize the customer age group using the Data step but it shows an error in the code (Statement is not valid). Could you please check and let me know what is the mistake in the code? Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Age_group;
set Age;
if Age =&amp;gt; 10 then 'years0-10';
else if Age =&amp;gt; 20 then 'years11-20';
else if Age =&amp;gt; 30 then 'years21-30';
else age = 'Others';
run;

Error Log:
29         Data Age_group;
30         set Age;
31         if Age =&amp;gt; 10 then 'years0-10';
                             ___________
                             180
32         else if Age =&amp;gt; 20 then 'years11-20';
                                  ____________
                                  180
33         else if Age =&amp;gt; 30 then 'years21-30';
                                  ____________
                                  180
ERROR 180-322: Statement is not valid or it is used out of proper order.

34         else age = 'Others';
35         run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      34:12   
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.AGE_GROUP may be incomplete.  When this step was stopped there were 0 observations and 65 variables.
WARNING: Data set WORK.AGE_GROUP was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              2341.31k
      OS Memory           31596.00k
2                                                          The SAS System                         09:27 Wednesday, December 14, 2022

      Timestamp           12/14/2022 01:48:40 PM
      Step Count                        71  Switch Count  0
      &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Dec 2022 13:51:41 GMT</pubDate>
    <dc:creator>Sandeep77</dc:creator>
    <dc:date>2022-12-14T13:51:41Z</dc:date>
    <item>
      <title>I want to categorize the age group and I am using the Data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849626#M37138</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am trying to categorize the customer age group using the Data step but it shows an error in the code (Statement is not valid). Could you please check and let me know what is the mistake in the code? Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Age_group;
set Age;
if Age =&amp;gt; 10 then 'years0-10';
else if Age =&amp;gt; 20 then 'years11-20';
else if Age =&amp;gt; 30 then 'years21-30';
else age = 'Others';
run;

Error Log:
29         Data Age_group;
30         set Age;
31         if Age =&amp;gt; 10 then 'years0-10';
                             ___________
                             180
32         else if Age =&amp;gt; 20 then 'years11-20';
                                  ____________
                                  180
33         else if Age =&amp;gt; 30 then 'years21-30';
                                  ____________
                                  180
ERROR 180-322: Statement is not valid or it is used out of proper order.

34         else age = 'Others';
35         run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      34:12   
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.AGE_GROUP may be incomplete.  When this step was stopped there were 0 observations and 65 variables.
WARNING: Data set WORK.AGE_GROUP was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              2341.31k
      OS Memory           31596.00k
2                                                          The SAS System                         09:27 Wednesday, December 14, 2022

      Timestamp           12/14/2022 01:48:40 PM
      Step Count                        71  Switch Count  0
      &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 13:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849626#M37138</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-12-14T13:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: I want to categorize the age group and I am using the Data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849637#M37139</link>
      <description>&lt;P&gt;There are 2 main problems here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You're missing the age = part in a few of your lines.&lt;/LI&gt;
&lt;LI&gt;You have a numeric variable Age in your data and you try to define a character variable named age. This will fail.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code should look something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Age_group;
set sashelp.class;
if      Age =&amp;gt; 10 then agegroup = 'years0-10';
else if Age =&amp;gt; 20 then agegroup = 'years11-20';
else if Age =&amp;gt; 30 then agegroup = 'years21-30';
else                   agegroup = 'Others';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 13:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849637#M37139</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-14T13:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: I want to categorize the age group and I am using the Data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849640#M37141</link>
      <description>&lt;P&gt;In my opinion, a superior method to handling this is custom formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value agef
         0-10='Years 0-10'
         11-20='Years 11-20'
         21-30='Years 21-30';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then assign the format to the variable in a DATA step or PROC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format age agef.;&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;As a style issue, when you do this replacement of a numeric variable with text, using either your method or my method, make it look like proper English (or whatever language you are using), as I have done with Years 0-10 instead of years0-10 as you have done. Or even better, remove the Years from the value since everyone understands that a variable named age implies you are using years.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 14:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849640#M37141</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-14T14:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: I want to categorize the age group and I am using the Data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849641#M37142</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 14:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/I-want-to-categorize-the-age-group-and-I-am-using-the-Data-step/m-p/849641#M37142</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-12-14T14:02:42Z</dc:date>
    </item>
  </channel>
</rss>

