<?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 How to merge two categorical groups within a single variable already existing in same dataset? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800164#M33188</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently trying to merge two categories within a single variable together. The variable is new_cat, and it currently has the levels of "Low" "moderate" and "high". I am trying to group "moderate" and "high" together as there aren't many values in the 'high' group. All of the information is within the same dataset which I've named work.newdt. I am unsure if I should somehow create a new variable with only two levels or merge the two levels in the already existing variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 14:27:36 GMT</pubDate>
    <dc:creator>Rose2</dc:creator>
    <dc:date>2022-03-04T14:27:36Z</dc:date>
    <item>
      <title>How to merge two categorical groups within a single variable already existing in same dataset?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800164#M33188</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently trying to merge two categories within a single variable together. The variable is new_cat, and it currently has the levels of "Low" "moderate" and "high". I am trying to group "moderate" and "high" together as there aren't many values in the 'high' group. All of the information is within the same dataset which I've named work.newdt. I am unsure if I should somehow create a new variable with only two levels or merge the two levels in the already existing variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 14:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800164#M33188</guid>
      <dc:creator>Rose2</dc:creator>
      <dc:date>2022-03-04T14:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two categorical groups within a single variable already existing in same dataset?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800185#M33189</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/418776"&gt;@Rose2&lt;/a&gt;&amp;nbsp; you can do this within the datastep using an IF statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.cars_short;
set sashelp.cars;
if make in ('Audi','BMW','Mercedes-Benz') then make_short = 'Luxury German';
else make_short = make;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also use a CASE statement via PROC SQL.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Hope that helps&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 15:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800185#M33189</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2022-03-04T15:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two categorical groups within a single variable already existing in same dataset?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800194#M33190</link>
      <description>&lt;P&gt;I attempted&amp;nbsp;&lt;/P&gt;&lt;P&gt;if new_dt_categories in ('Moderate Distress', 'Highâ€Ž/Extreme Distress') then new_dt_cat2= 'Moderate/Extreme';&lt;BR /&gt;else new_dt_categories2=new_dt_categories;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but when I did proc freq, it still had separate categories, and now they were numbered instead of being named in the table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 15:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800194#M33190</guid>
      <dc:creator>Rose2</dc:creator>
      <dc:date>2022-03-04T15:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two categorical groups within a single variable already existing in same dataset?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800206#M33191</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/418776"&gt;@Rose2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I attempted&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if new_dt_categories in ('Moderate Distress', 'Highâ€Ž/Extreme Distress') then new_dt_cat2= 'Moderate/Extreme';&lt;BR /&gt;else new_dt_categories2=new_dt_categories;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I did proc freq, it still had separate categories, and now they were numbered instead of being named in the table.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What you described makes it sound like your original variable is numeric (or if character has digit strings in it) and is being displayed using a user defined format that converts those numbers into the text you used in IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using PUT() in your IF.&amp;nbsp; Or even easier use VVALUE() function since then you don't need to know what format is attached to the variable.&amp;nbsp; Also make sure to define the new variable long enough to hold the longest possible value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length new_dt_cat2 $200;
if vvalue(new_dt_categories) in ('Moderate Distress', 'Highâ€Ž/Extreme Distress') then new_dt_cat2= 'Moderate/Extreme';
else new_dt_categories2=vvalue(new_dt_categories);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note you could also just make a new format that collapses those categories into one.&amp;nbsp; That might be enough for what you are doing.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 15:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800206#M33191</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-04T15:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two categorical groups within a single variable already existing in same dataset?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800313#M33192</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;Run a PROC CONTENTS on your dataset to see the attributes of your variable(s). Your data step codes have to deal with the raw, unformatted values to work.&lt;/P&gt;
&lt;P&gt;If the values are formatted, a simple change of the format allows statistical procedures to use another grouping.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 07:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-merge-two-categorical-groups-within-a-single-variable/m-p/800313#M33192</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-05T07:11:31Z</dc:date>
    </item>
  </channel>
</rss>

