<?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 Delete first word before first space in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693090#M211286</link>
    <description>&lt;P&gt;Hi y'all i hope you're doing fine,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on a cars database and i'm having a little hard time extract name and surname of cars, my table looks like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;Brand&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CITROEN C3 AIRCROSS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DS3 CROSSBACK E-TENSE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OPEL GRANDLAND X&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i wanna create two variables one named Make ( for the brand name ) and the other Model (for the brand model), so far so good for the Make ( because it's the first string before the space ) so with this i've succeeded getting my Make&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Make = scan(brand,1,' ');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now it's a little bit harder to for the model i've had few ideas but none was effective, for my model variable i want everything after the first space, i thought first to ease the process use tranwrd function and replace all my spaces with a underscore but it replaces also the space in the end with underscore, for the substr function i need the position for each observation wich a little bit hard&amp;nbsp; since each observation is different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any hint for me to make this work and all the strings after the first space please ?&lt;/P&gt;</description>
    <pubDate>Wed, 21 Oct 2020 08:58:12 GMT</pubDate>
    <dc:creator>skavli</dc:creator>
    <dc:date>2020-10-21T08:58:12Z</dc:date>
    <item>
      <title>Delete first word before first space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693090#M211286</link>
      <description>&lt;P&gt;Hi y'all i hope you're doing fine,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on a cars database and i'm having a little hard time extract name and surname of cars, my table looks like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;Brand&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CITROEN C3 AIRCROSS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DS3 CROSSBACK E-TENSE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OPEL GRANDLAND X&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i wanna create two variables one named Make ( for the brand name ) and the other Model (for the brand model), so far so good for the Make ( because it's the first string before the space ) so with this i've succeeded getting my Make&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Make = scan(brand,1,' ');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now it's a little bit harder to for the model i've had few ideas but none was effective, for my model variable i want everything after the first space, i thought first to ease the process use tranwrd function and replace all my spaces with a underscore but it replaces also the space in the end with underscore, for the substr function i need the position for each observation wich a little bit hard&amp;nbsp; since each observation is different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any hint for me to make this work and all the strings after the first space please ?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 08:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693090#M211286</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-10-21T08:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Delete first word before first space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693092#M211287</link>
      <description>&lt;P&gt;Use CALL SCAN and then SUBSTR:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input brand $50.;
datalines;
CITROEN C3 AIRCROSS
DS3 CROSSBACK E-TENSE
OPEL GRANDLAND X
;

data want;
set have;
make = scan(brand,1);
call scan(brand,1,p,l);
model = substr(brand,l+2);
drop p l;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 09:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693092#M211287</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-21T09:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Delete first word before first space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693093#M211288</link>
      <description>Thanks that works perfectly, i gotta go see what that call function do and remember it.&lt;BR /&gt;Greetings sir</description>
      <pubDate>Wed, 21 Oct 2020 09:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693093#M211288</guid>
      <dc:creator>skavli</dc:creator>
      <dc:date>2020-10-21T09:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Delete first word before first space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693094#M211289</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model = substr(brand, length(make)+2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could, of course, use a regular expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   
   length rx 8 make model $ 50;
   retain rx;
   drop rx;
   
   if _n_ = 1 then do;
      rx = prxparse('/(\S+) (.+)/');
   end;
   
   if prxmatch(rx, brand) then do;
      make = prxposn(rx, 1, brand);
      model = prxposn(rx, 2, brand);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 09:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693094#M211289</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-10-21T09:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delete first word before first space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693095#M211290</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299342"&gt;@skavli&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi y'all i hope you're doing fine,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working on a cars database and i'm having a little hard time extract name and surname of cars, my table looks like this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;Brand&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CITROEN C3 AIRCROSS&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;DS3 CROSSBACK E-TENSE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;OPEL GRANDLAND X&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now i wanna create two variables one named Make ( for the brand name ) and the other Model (for the brand model), so far so good for the Make ( because it's the first string before the space ) so with this i've succeeded getting my Make&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Make = scan(brand,1,' ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now it's a little bit harder to for the model i've had few ideas but none was effective, for my model variable i want everything after the first space, i thought first to ease the process use tranwrd function and replace all my spaces with a underscore but it replaces also the space in the end with underscore, for the substr function i need the position for each observation wich a little bit hard&amp;nbsp; since each observation is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any hint for me to make this work and all the strings after the first space please ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Edit your original post, using a SAS datastep with datalines statements to create your sample dataset.&amp;nbsp; Don't paste in a screenshot since if forces *us* to create *your* sample dataset.&amp;nbsp; Post using the "Insert SAS code" icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length somevariable $200;
   somevariable='foo    bar blah';
run;

data want1;
   set have;
   length make $100 model $100;
   pos=index(somevariable,' ');
   if pos then do;
      make=substr(somevariable,1,pos);
      model=substr(somevariable,pos+1);
      model=strip(model);
   end;
run;

data want2;
   set have;
   length make $100 model $100;
   rx=prxparse('/(.*?) (.*)/o');
   if prxmatch(rx,somevariable) then do;
      make=prxposn(rx,1,somevariable);
      model=prxposn(rx,2,somevariable);
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 09:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-first-word-before-first-space/m-p/693095#M211290</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2020-10-21T09:21:43Z</dc:date>
    </item>
  </channel>
</rss>

