<?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: How to add and delete observations within a range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284606#M58056</link>
    <description>&lt;P&gt;As you have learned the hard way, it is good not to modify the original data.&amp;nbsp; Now that you have done it, deleting the extra observations is a simple data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA haveless;&lt;/P&gt;
&lt;P&gt;SET have;&lt;/P&gt;
&lt;P&gt;IF _n_&amp;gt;2010 THEN DELETE;&amp;nbsp; *Assumes added rows at the end;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still have the original data, a better approach to augmentation might be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA havemdd0;&lt;/P&gt;
&lt;P&gt;DO _I_ =1871 to 2010;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; mdd=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; OUTPUT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; END;&lt;/P&gt;
&lt;P&gt;DROP _i_;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA have2;&lt;/P&gt;
&lt;P&gt;SET have havemdd0;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jul 2016 17:53:46 GMT</pubDate>
    <dc:creator>Doc_Duke</dc:creator>
    <dc:date>2016-07-14T17:53:46Z</dc:date>
    <item>
      <title>How to add and delete observations within a range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284400#M58051</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I use SAS 9.4 and I have a dataset with a variable called "mdd", which has 1870 observations. I hope to get a descriptive statistics of mdd with 2010 observations (observation 1871-2010 will be assigned values of 0). I used the following code:&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;PROC UNIVARIATE DATA=have;
VAR mdd;
RUN;&lt;/STRONG&gt; &lt;/PRE&gt;&lt;P&gt;But it only offers info about the 1870 observations.&lt;/P&gt;&lt;P&gt;So I used the following codes to add rows:&lt;/P&gt;&lt;PRE&gt;proc sql;
insert into have
set mdd=0&lt;BR /&gt;set mdd=0&lt;BR /&gt;...&lt;BR /&gt;set mdd=0;&lt;/PRE&gt;&lt;P&gt;This is troublesome and I add observations to 2019 by accident. Now I want to delete the observations from 2011-2019 but I do not know how to do that. So is there a code to directly add &amp;nbsp;mdd=0 from observation 1871 to 2010? Also, is there a code to delete observations in a range?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 17:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284400#M58051</guid>
      <dc:creator>Therain</dc:creator>
      <dc:date>2016-07-14T17:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and delete observations within a range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284605#M58055</link>
      <description>&lt;P&gt;Looks like all you need to do is extend a dataset with blank observations. You could use something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have end=done;
output;
if done then do;
	mdd = 0;
	do i = 1871 to 2010; output; end;
	end;
drop i;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 17:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284605#M58055</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-14T17:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and delete observations within a range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284606#M58056</link>
      <description>&lt;P&gt;As you have learned the hard way, it is good not to modify the original data.&amp;nbsp; Now that you have done it, deleting the extra observations is a simple data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA haveless;&lt;/P&gt;
&lt;P&gt;SET have;&lt;/P&gt;
&lt;P&gt;IF _n_&amp;gt;2010 THEN DELETE;&amp;nbsp; *Assumes added rows at the end;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still have the original data, a better approach to augmentation might be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA havemdd0;&lt;/P&gt;
&lt;P&gt;DO _I_ =1871 to 2010;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; mdd=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; OUTPUT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; END;&lt;/P&gt;
&lt;P&gt;DROP _i_;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA have2;&lt;/P&gt;
&lt;P&gt;SET have havemdd0;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 17:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284606#M58056</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2016-07-14T17:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and delete observations within a range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284620#M58059</link>
      <description>Thank you! It works!</description>
      <pubDate>Thu, 14 Jul 2016 18:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-and-delete-observations-within-a-range/m-p/284620#M58059</guid>
      <dc:creator>Therain</dc:creator>
      <dc:date>2016-07-14T18:34:25Z</dc:date>
    </item>
  </channel>
</rss>

