<?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: create two new variables based on values of original variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318745#M69877</link>
    <description>&lt;PRE&gt;

data have;
input category $25. ;
cards;
APPLEPLUS
A1
A2
3
4
BANANAPLUS
3
B5
6
PEARPLUS
2
Q15
C17
3
Z02
;
RUN;
data want;
 set have;
 length cat $ 40;
 retain cat;
 if anydigit(category)=0 then do;
  cat=category;delete;
 end;
run;

&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Dec 2016 03:18:36 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-12-14T03:18:36Z</dc:date>
    <item>
      <title>create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318698#M69854</link>
      <description>&lt;P&gt;Thanks a lot in advance, friends. Below are samples of both what i have and what i want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input category $25. ;&lt;BR /&gt;cards;&lt;BR /&gt;APPLEPLUS&lt;BR /&gt;A1&lt;BR /&gt;A2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;BANANAPLUS&lt;BR /&gt;3&lt;BR /&gt;B5&lt;BR /&gt;6&lt;BR /&gt;PEARPLUS&lt;BR /&gt;2&lt;BR /&gt;Q15&lt;BR /&gt;C17&lt;BR /&gt;3&lt;BR /&gt;Z02&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA WANT;&lt;BR /&gt;input category $25. category1 $10. ;;&lt;BR /&gt;cards;&lt;BR /&gt;APPLEPLUS &amp;nbsp;A1&lt;BR /&gt;APPLEPLUS &amp;nbsp;A2&lt;BR /&gt;APPLEPLUS &amp;nbsp;3&lt;BR /&gt;APPLEPLUS &amp;nbsp;4&lt;BR /&gt;BANANAPLUS &amp;nbsp;3&lt;BR /&gt;BANANAPLUS &amp;nbsp;B5&lt;BR /&gt;BANANAPLUS &amp;nbsp; 6&lt;BR /&gt;PEARPLUS &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;PEARPLUS &amp;nbsp; &amp;nbsp;Q15&lt;BR /&gt;PEARPLUS &amp;nbsp; &amp;nbsp; C17&lt;BR /&gt;PEARPLUS &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;PEARPLUS Z02&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using the following code, but it doesnt get me much. The values such as appleplus, BANANAPLUS etc are typically long all character but the others are much smaller and are either numerical or starting with an alphabet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA WANT;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;LENGTH CATEGORY1 $25.;&lt;BR /&gt;IF LENGTH(CATEGORY)&amp;gt; 7 THEN CATEGORY1 = CATEGORY;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 21:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318698#M69854</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-13T21:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318707#M69858</link>
      <description>&lt;P&gt;Using these notions, you should be able to construct a data step to do the task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Rename category to category1 when reading HAVE, so now category is a new variable and category1 is old.&lt;/LI&gt;
&lt;LI&gt;Instead of looking for a long word to determine the presence of a new category, why not look for the string 'PLUS', as in&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if find(category1,'PLUS') then category=category1;&lt;/LI&gt;
&lt;LI&gt;output only if #2 is not true (because it will have category, but not category1).&lt;/LI&gt;
&lt;LI&gt;Retain the "new" variable category, to carray foward to the subsequent category1 series.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also do analogous logic when reading in the raw data, i.e. straight from raw data to WANT, no need for HAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 21:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318707#M69858</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-13T21:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318713#M69861</link>
      <description>&lt;P&gt;One possibility:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input text $25. ;&lt;/P&gt;
&lt;P&gt;length category $ 25 category1 $ 10;&lt;/P&gt;
&lt;P&gt;if length(text) &amp;gt; 7 then category=text;&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; category1=text;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain category;&lt;BR /&gt;cards;&lt;BR /&gt;APPLEPLUS&lt;BR /&gt;A1&lt;BR /&gt;A2&lt;BR /&gt;3&lt;BR /&gt;4&lt;/P&gt;
&lt;P&gt;BANANAPLUS&lt;BR /&gt;3&lt;BR /&gt;B5&lt;BR /&gt;6&lt;BR /&gt;PEARPLUS&lt;BR /&gt;2&lt;BR /&gt;Q15&lt;BR /&gt;C17&lt;BR /&gt;3&lt;BR /&gt;Z02&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318713#M69861</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-13T22:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318718#M69864</link>
      <description>&lt;P&gt;Thanks Astounding, but not sure what you got here. I mean my want will give you the final output i want, so not sure what you mean by cards statement in your solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the names such as appleplus and bananaplus are examples only, real names are 2-3 word characters. I have around 30,000 records.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318718#M69864</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-13T22:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318719#M69865</link>
      <description>&lt;P&gt;It's a one-step solution that skips creating HAVE and produces WANT from the original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess if you already have the data set HAVE, you could get WANT with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (rename=(category=text));&lt;/P&gt;
&lt;P&gt;if length(text) &amp;gt; 7 then category=text;&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; category1=text;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain category;&lt;/P&gt;
&lt;P&gt;drop text;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318719#M69865</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-13T22:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318745#M69877</link>
      <description>&lt;PRE&gt;

data have;
input category $25. ;
cards;
APPLEPLUS
A1
A2
3
4
BANANAPLUS
3
B5
6
PEARPLUS
2
Q15
C17
3
Z02
;
RUN;
data want;
 set have;
 length cat $ 40;
 retain cat;
 if anydigit(category)=0 then do;
  cat=category;delete;
 end;
run;

&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2016 03:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318745#M69877</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-14T03:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: create two new variables based on values of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318932#M69937</link>
      <description>&lt;P&gt;Thanks KSHARP. This one works as well, perhaps little better because there is no dependence on length.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 13:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-two-new-variables-based-on-values-of-original-variable/m-p/318932#M69937</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-14T13:56:28Z</dc:date>
    </item>
  </channel>
</rss>

