<?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 Create a new row using another row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522908#M142017</link>
    <description>&lt;P&gt;I have a data set that looks like the following:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Column 1  Column 2   Column 3
Data                4                3 
Data 1             3                2 
Data 2             3                4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to insert a&amp;nbsp;row under the title names&amp;nbsp;that duplicates&amp;nbsp; row Data 2 renamed.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Column 1  Column 2   Column 3
New                3                4
Data                4                3 
Data 1             3                2 
Data 2             3                4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I do so? I've seen this used:&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; totals as&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;but I'm just looking for the easiest way.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Dec 2018 17:06:24 GMT</pubDate>
    <dc:creator>serena13lee</dc:creator>
    <dc:date>2018-12-20T17:06:24Z</dc:date>
    <item>
      <title>Create a new row using another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522908#M142017</link>
      <description>&lt;P&gt;I have a data set that looks like the following:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Column 1  Column 2   Column 3
Data                4                3 
Data 1             3                2 
Data 2             3                4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to insert a&amp;nbsp;row under the title names&amp;nbsp;that duplicates&amp;nbsp; row Data 2 renamed.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Column 1  Column 2   Column 3
New                3                4
Data                4                3 
Data 1             3                2 
Data 2             3                4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I do so? I've seen this used:&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; totals as&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;but I'm just looking for the easiest way.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 17:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522908#M142017</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2018-12-20T17:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new row using another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522912#M142019</link>
      <description>&lt;P&gt;Assuming i Understand your requirement--&amp;gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input (Column1- Column3) (&amp;amp; $8.);
cards;
Data                4                3 
Data 1             3                2 
Data 2             3                4
;

data want;
if _n_=1 then do;
set have(where=(column1='Data 2'));
Column1='New';
output;
end;
set have;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 17:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522912#M142019</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-20T17:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new row using another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522913#M142020</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Column1- Column3) (&amp;amp; $8.);
cards;
Data                4                3 
Data 1             3                2 
Data 2             3                4
;

proc sql;
create table want as
select 'New' as Column1,Column2,Column3 from have(where=(column1='Data 2'))
union all
select * from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 17:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522913#M142020</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-20T17:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new row using another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522914#M142021</link>
      <description>&lt;P&gt;More fun&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input (Column1- Column3) (&amp;amp; $8.);
cards;
Data                4                3 
Data 1             3                2 
Data 2             3                4
;
data want;
set have(where=(column1='Data 2'))  have;
if _n_=1 then Column1='New';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 17:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522914#M142021</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-20T17:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new row using another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522915#M142022</link>
      <description>&lt;P&gt;In essence, you want to concatenate two data sets:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A single observation data set comprised of observation &lt;STRIKE&gt;2&lt;/STRIKE&gt;3 of have&lt;/LI&gt;
&lt;LI&gt;Followed by all of have:&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This is a good situation to take advantage of the fact that the SET statement can take multiple data sources.&amp;nbsp; All you have to do is define those sources to produce #1 and #2 above:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Column1- Column3) (&amp;amp; $8.);
cards;
Data                4                3 
Data 1             3                2 
Data 2             3                4
;

data want;
  set have (firstobs=3 obs=3)  have;
  if _n_=1 the columns1='New';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code above edited from ("firstobs=2 obs=2") to ("firstobs=3 obs=3") per &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s acute note.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first argument of SET tells sas to read from data set HAVE, starting at observation &lt;STRIKE&gt;2&lt;/STRIKE&gt;3 and ending at observation &lt;STRIKE&gt;2&lt;/STRIKE&gt;3.&amp;nbsp; The second argument says to read all of HAVE, from the 1st through last observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "if _n_=1" test makes a change only for the first iteration of the data step - i.e. the 1st incoming observation.&amp;nbsp; Note it does NOT mean the first observation from each of the concatenated data sources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if the criterion for the single prefix record is, as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;suggested, then change the SET statement to the below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (where=(column1='Data 2') obs=1)  have;
  if _n_=1 the columns1='New';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This tells SAS to read the first (and only the first) observation that has column1='Data 2'.&amp;nbsp; Note the "obs=1" only applies to the observations that pass the WHERE filter.&amp;nbsp; So observations 1 (column1='Data') and 2 (column1='Data 1') are not counted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 19:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522915#M142022</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-20T19:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new row using another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522918#M142024</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; is this a typo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;firstobs&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; obs&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;  have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Shouldn't it be&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;firstobs&lt;SPAN class="token operator"&gt;=3&lt;/SPAN&gt; obs&lt;SPAN class="token operator"&gt;=3&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;  have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw, I like the&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;column1&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Data 2'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; obs&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;  have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Very neat &amp;amp; efficient. Kudos!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 17:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-row-using-another-row/m-p/522918#M142024</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-20T17:42:52Z</dc:date>
    </item>
  </channel>
</rss>

