<?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: Insert observations in the middle of dataset and insert new data for a single variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759253#M239896</link>
    <description>&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   set sashelp.class;
   output;

   if Name = "James" then do;
      call missing (of _ALL_);
      sex = "T1";
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Aug 2021 09:39:39 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-08-04T09:39:39Z</dc:date>
    <item>
      <title>Insert observations in the middle of dataset and insert new data for a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759251#M239894</link>
      <description>&lt;P&gt;Dear SAS experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to insert a new observation after "James" (3rd observation) which includes missing data for all variables except for Sex to which I want to assign the value "T1" (just as an example). One way of doing it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Inserting a new observation after _N_=3 (after "James") in the dataset;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;length Sex $2;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;output;&lt;BR /&gt;if _N_ =3 then do;&lt;BR /&gt;Sex="T1"; /* Only place to insert non-missing data. Missing data for the rest of the variables. */&lt;BR /&gt;Name=".";&lt;BR /&gt;Age=.;&lt;BR /&gt;Height=.;&lt;BR /&gt;Weight=.;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Instead of basing the insert of the new observation on _N_=3 could I somehow simply state that an observation should be introduced after Name="James"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Above I write that each of the remaining variables should be "." or .. Could I write this in a more simple way, i.e. that all remaining variables should be missing (or "." when referring to character variables)? This is especially relevant in cases where the above procedure should be performed in dataset which contain many variables (not just 5 as in class).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 09:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759251#M239894</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-08-04T09:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Insert observations in the middle of dataset and insert new data for a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759253#M239896</link>
      <description>&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   set sashelp.class;
   output;

   if Name = "James" then do;
      call missing (of _ALL_);
      sex = "T1";
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Aug 2021 09:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759253#M239896</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-08-04T09:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Insert observations in the middle of dataset and insert new data for a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759259#M239899</link>
      <description>&lt;P&gt;This must be an academic problem. If the order of observations is important then you need to sort the table after inserting new obs. That's the only way SAS will "know" that the table is sorted.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 10:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759259#M239899</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-04T10:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Insert observations in the middle of dataset and insert new data for a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759264#M239902</link>
      <description>Dear Peter&lt;BR /&gt;&lt;BR /&gt;Perfect, yes - this is what I was looking for.&lt;BR /&gt;&lt;BR /&gt;Can I do it multiple times in the same data set? Could I e.g. perform the following operation - "Jeffrey" and T2 - at the same time:&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;output;&lt;BR /&gt;&lt;BR /&gt;if Name = "Jeffrey" then do;&lt;BR /&gt;call missing (of _ALL_);&lt;BR /&gt;sex = "T2";&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Thank you</description>
      <pubDate>Wed, 04 Aug 2021 10:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-observations-in-the-middle-of-dataset-and-insert-new-data/m-p/759264#M239902</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-08-04T10:11:42Z</dc:date>
    </item>
  </channel>
</rss>

