<?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: Categorizing one variable into two in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817635#M34560</link>
    <description>&lt;P&gt;Knowing delimiters to use with Scan likely is all you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this. The first data step is just to create example data.&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines truncover;
   input  Tectonic_Setting $50.;
datalines;
Rift Zone / Continental Crust (&amp;gt;25 km)
Intrastate / Continental Crust (&amp;gt;25 km)
Subsection Zone / Continental Crust (&amp;gt;25 km)
Rift Zone / Intermediate Crust (15-25 km)
Rift Zone / Oceanic Crust (&amp;lt; 15 km)
;

data want;
    set have;
    length plate_type $ 16 Crust_type $ 19;
    plate_type = scan(tectonic_setting,1,'/');
    crust_type = strip(scan(tectonic_setting,2,'/('));
run;&lt;/PRE&gt;
&lt;P&gt;You didn't describe your problem but from the code you used all of the default delimiters would have been used so instead of "Rift Zone" you would only get "Rift". It is extremely likely, that depending on actual order of data that the length assigned to the Plate_type variable wasn't long enough to hold all of "interstate". So first we set a length for the desired variables long enough to hold the longest expected value (shown in your list).&lt;/P&gt;
&lt;P&gt;Then we specify a specific character for the Scan function so that we get the whole value. The first scan uses just the / character but the second specifies use of / and ( so that the depths don't get included. I also use Strip function to remove the leading space that would occur.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to learn that gets very important when manipulating character values is that if you do not set lengths of variables SAS will set them based on the first result or use. So "short" values typically indicate a length wasn't set.&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>Mon, 13 Jun 2022 16:18:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-06-13T16:18:44Z</dc:date>
    <item>
      <title>Categorizing one variable into two</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817629#M34559</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Could you please help me regarding the above-mentioned issue. I have data set and I want to categorize the variable tectonic_setting into two new variables:&lt;BR /&gt;•Plate_type: Intrastate, Rift zone, Subsection zone&lt;BR /&gt;•Crust_type: Continental crust, Intermediate crust, Ocean crust&lt;/P&gt;&lt;P&gt;I used the following code:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;Plate_type = SCAN(tectonic_setting,1);&lt;BR /&gt;Crust_type = SCAN(tectonic_setting,3);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;It works partially i.e. some part is coming and some part is not coming as a output.&lt;/P&gt;&lt;P&gt;Here is the some data:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Tectonic_Setting&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Rift Zone / Continental Crust (&amp;gt;25 km)&lt;/P&gt;&lt;P&gt;Intrastate / Continental Crust (&amp;gt;25 km)&lt;/P&gt;&lt;P&gt;Subsection Zone / Continental Crust (&amp;gt;25 km)&lt;/P&gt;&lt;P&gt;Rift Zone / Intermediate Crust (15-25 km)&lt;/P&gt;&lt;P&gt;Rift Zone / Oceanic Crust (&amp;lt; 15 km)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am also giving a portion of data set as an attachment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking for your kind response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jun 2022 04:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817629#M34559</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-12T04:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Categorizing one variable into two</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817635#M34560</link>
      <description>&lt;P&gt;Knowing delimiters to use with Scan likely is all you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this. The first data step is just to create example data.&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines truncover;
   input  Tectonic_Setting $50.;
datalines;
Rift Zone / Continental Crust (&amp;gt;25 km)
Intrastate / Continental Crust (&amp;gt;25 km)
Subsection Zone / Continental Crust (&amp;gt;25 km)
Rift Zone / Intermediate Crust (15-25 km)
Rift Zone / Oceanic Crust (&amp;lt; 15 km)
;

data want;
    set have;
    length plate_type $ 16 Crust_type $ 19;
    plate_type = scan(tectonic_setting,1,'/');
    crust_type = strip(scan(tectonic_setting,2,'/('));
run;&lt;/PRE&gt;
&lt;P&gt;You didn't describe your problem but from the code you used all of the default delimiters would have been used so instead of "Rift Zone" you would only get "Rift". It is extremely likely, that depending on actual order of data that the length assigned to the Plate_type variable wasn't long enough to hold all of "interstate". So first we set a length for the desired variables long enough to hold the longest expected value (shown in your list).&lt;/P&gt;
&lt;P&gt;Then we specify a specific character for the Scan function so that we get the whole value. The first scan uses just the / character but the second specifies use of / and ( so that the depths don't get included. I also use Strip function to remove the leading space that would occur.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to learn that gets very important when manipulating character values is that if you do not set lengths of variables SAS will set them based on the first result or use. So "short" values typically indicate a length wasn't set.&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>Mon, 13 Jun 2022 16:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817635#M34560</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-13T16:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Categorizing one variable into two</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817698#M34563</link>
      <description>Hi Ballardw,&lt;BR /&gt;Thanks for your kind support and explanation about the code usable for the data. Yes, the code you provided is working perfectly. As a new user, I am learning and enjoying this platform. Thanks again.</description>
      <pubDate>Mon, 13 Jun 2022 01:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Categorizing-one-variable-into-two/m-p/817698#M34563</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-13T01:44:04Z</dc:date>
    </item>
  </channel>
</rss>

