<?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: pull a word out of a character string and join it with a different char string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424460#M104522</link>
    <description>&lt;P&gt;if you can show an example of what you have as data and what you want as data, it will be very easy for someone to help you&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jan 2018 21:47:18 GMT</pubDate>
    <dc:creator>kiranv_</dc:creator>
    <dc:date>2018-01-02T21:47:18Z</dc:date>
    <item>
      <title>pull a word out of a character string and join it with a different char string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424459#M104521</link>
      <description>&lt;LI-SPOILER&gt;&amp;nbsp;&lt;/LI-SPOILER&gt;
&lt;P&gt;Hi!&amp;nbsp; I'm trying to pull a word out of a character string and join it with a different char string separated by colon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For variable DSAE, I have values that look like this:&lt;/P&gt;
&lt;P&gt;AE: (1) hypertension 16-NOV-2017.&amp;nbsp; I need to pull out the 'hypertension'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I need to join with another variable&amp;nbsp;DSDE , with the two values separated by colon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if DSAE ne '' then reason = strip(DSDE) || ': ' || scan(DSAE ,3,' ');&lt;BR /&gt; else if DSAE = '' then reason = strip(DSDE);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But my new variable&amp;nbsp; REASON is not displaying the new string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 21:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424459#M104521</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-01-02T21:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: pull a word out of a character string and join it with a different char string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424460#M104522</link>
      <description>&lt;P&gt;if you can show an example of what you have as data and what you want as data, it will be very easy for someone to help you&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 21:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424460#M104522</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-02T21:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: pull a word out of a character string and join it with a different char string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424464#M104525</link>
      <description>&lt;P&gt;There's no particular reason that shouldn't work as you coded it in theory - see this example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
dsae='AE: (1) hypertension 16-NOV-2017';
dsde='something else';

if DSAE ne '' then reason = strip(DSDE) || ': ' || scan(DSAE ,3,' ');
else if DSAE = '' then reason = strip(DSDE);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, you may run into issues with lengths, which could be keeping you from getting your correct result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also would note that the `else if` there isn't really necessary, it seems like it should just be `else`.&amp;nbsp; While those two conditions should be&amp;nbsp;the full set of possibilities, you run into issues where you could have a mistake that makes both of them false.&amp;nbsp; (I'm also not sure what happens if that is processed in SQL for example, where '' and ' ' are different, and NULL is something yet different.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would code it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length reason $50;
  dsae='AE: (1) hypertension 16-NOV-2017';
  dsde='something else';

  reason = catx(': ',DSDE,scan(DSAE ,3,' '));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But mostly that's just stylistic differences.&amp;nbsp; The ELSE is not necessary here as CATX will not add the delimiter if the argument is blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the above doesn't work for you, you'll need to give some example data that reproduces your particular issue, and let us know if there's anything complicated here like a non-SAS data source on the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First try adding a LENGTH statement that's sufficiently long, though, I think that could well be part of your issue.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 22:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424464#M104525</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2018-01-02T22:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: pull a word out of a character string and join it with a different char string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424471#M104526</link>
      <description>&lt;P&gt;All you need is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length reason $100;
reason = catx(": ", DSDE, scan(DSAE ,3 ,' '));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jan 2018 22:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424471#M104526</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-02T22:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: pull a word out of a character string and join it with a different char string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424646#M104567</link>
      <description>&lt;P&gt;Perhaps you have been experimenting with this for a while and might find that REASON is already part of your incoming data set. &amp;nbsp;In that case, you may need a longer length:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;length reason $ 100;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;*** then re-set the value for REASON, using CATX;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If REASON is too short, and already defined, it may not be long enough to hold the new string.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pull-a-word-out-of-a-character-string-and-join-it-with-a/m-p/424646#M104567</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-03T18:05:27Z</dc:date>
    </item>
  </channel>
</rss>

