<?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 a new category for an existing variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688557#M24609</link>
    <description>Is it a single row you need to fix or do you need to ensure you have the years 2010 to 2014 for every company? &lt;BR /&gt;Those are two different problems with two different solutions.</description>
    <pubDate>Fri, 02 Oct 2020 16:05:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-10-02T16:05:47Z</dc:date>
    <item>
      <title>Create a new category for an existing variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688528#M24607</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering if someone could help me with the following issue. I&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;have a dataset that looks something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year&amp;nbsp; &amp;nbsp; &amp;nbsp; Company&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Substance&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Value&lt;/P&gt;&lt;P&gt;2011&amp;nbsp; &amp;nbsp; &amp;nbsp; Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.3&lt;/P&gt;&lt;P&gt;2012&amp;nbsp; &amp;nbsp; &amp;nbsp; Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4.3&lt;/P&gt;&lt;P&gt;2013&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6.8&lt;/P&gt;&lt;P&gt;2014&amp;nbsp; &amp;nbsp; &amp;nbsp; Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I create, in a datastep, one new row with the year 2010 and Company Max but where substance and value is empty?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Karoline&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 15:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688528#M24607</guid>
      <dc:creator>KarolineN</dc:creator>
      <dc:date>2020-10-02T15:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new category for an existing variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688552#M24608</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/341969"&gt;@KarolineN&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wondering if someone could help me with the following issue. I&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;have a dataset that looks something like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Year&amp;nbsp; &amp;nbsp; &amp;nbsp; Company&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Substance&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Value&lt;/P&gt;
&lt;P&gt;2011&amp;nbsp; &amp;nbsp; &amp;nbsp; Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.3&lt;/P&gt;
&lt;P&gt;2012&amp;nbsp; &amp;nbsp; &amp;nbsp; Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4.3&lt;/P&gt;
&lt;P&gt;2013&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6.8&lt;/P&gt;
&lt;P&gt;2014&amp;nbsp; &amp;nbsp; &amp;nbsp; Max&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I create, in a datastep, one new row with the year 2010 and Company Max but where substance and value is empty?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for any help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Karoline&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Assuming that you want something that actually does this for multiple companies this should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
   by company year;
run;
data want;
   set have;
   by company;
   output;
   if last.company then do;
      year=2010;
      call missing(substance,value);
      output;
   end;
run;

proc sort data=want;
   by company year;
run;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
   by company year;
run;
proc sql;
   create table temp as
   select distinct(company), 2010 as year
   from have
   order by company, year
   ;
quit;

data want;
   merge have temp;
   by company year;
run;
&lt;/PRE&gt;
&lt;P&gt;If multiple year values need to be created that is another story.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 15:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688552#M24608</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-02T15:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new category for an existing variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688557#M24609</link>
      <description>Is it a single row you need to fix or do you need to ensure you have the years 2010 to 2014 for every company? &lt;BR /&gt;Those are two different problems with two different solutions.</description>
      <pubDate>Fri, 02 Oct 2020 16:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688557#M24609</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-02T16:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new category for an existing variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688561#M24610</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are right. I realize I simplified it too much. I have data for several companies and I need to ensure I have the year 2010 - 2014 for all. But I do not want duplicates. That is, if a company already has data for 2010, I do not also want an empty row for to 2010 in addition.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Karoline&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 16:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688561#M24610</guid>
      <dc:creator>KarolineN</dc:creator>
      <dc:date>2020-10-02T16:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new category for an existing variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688564#M24612</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
proc sql;
    create table years as select distinct year from have;
    create table company as select distinct company from have;
    /* Cartesian join */
    create table all as select y.year,c.company from years as y,company as c; 
    create table want as select coalesce(h.year,a.year) as year,
        coalesce(h.company,a.company) as company,h.substance,h.value
        from have as h full join all as a by h.year=a.year and h.company=a.company
    order by calculated company,calculated year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is untested. If you want it tested, please supply a meaningful example data set following these instructions:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 16:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688564#M24612</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-02T16:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new category for an existing variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688678#M24626</link>
      <description>&lt;PRE&gt;data have;
input Year      Company    $    Substance     $         Value;
cards;
2011      Max                A                             2.3
2012      Max               B                              4.3
2013      Max               C                              6.8
2014      Max               A                               7.4
;

data want;
 if _n_=1 then do;
   if 0 then set have;
   year=2010; company='Max';output;
 end;
 set have;
 output;
run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Oct 2020 11:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-category-for-an-existing-variable/m-p/688678#M24626</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-03T11:46:38Z</dc:date>
    </item>
  </channel>
</rss>

