<?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 Adding an observation depending on other observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605878#M175865</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS 9.4 and I need help in adding a new observation depending on other observations.&lt;/P&gt;&lt;P&gt;I have a data set with people with 1 or more observations. I have an ID, group, study_start, study_end, group_date. I have more variables per observation that are irrelevant here. The other variables are the same for every ID, they don't change even if it is a new observation.&lt;/P&gt;&lt;P&gt;What I want is to add an observation IF the group_date is after study_start. Then I want an observation where group is 1 and study_start is the same as the previous one and study_end is the same as the previous group-date -1. I have organized it in descending year to make it easier to add an observation. It is not so important to get the study_end;&amp;nbsp;I can manage that once I get the new observation. It is however, important that I get all my variables copied to the new observation and that the group =1.&lt;/P&gt;&lt;P&gt;Hope somebody can help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID group study_start study_end group_date;

1 1 2013 2015 2013
1 2 2000 2012 2011

2 3 2000 2015 2004

3 2 2004 2009 2006

4 3 2009 2015 2009 
4 2 2006 2008 2006

run;

data want;
input ID group study_start study_end group_date;

1 1 2013 2015 2013
1 2 2000 2012 2011
1 1 2000 2010 

2 3 2000 2015 2004
2 1 2000 2003

3 2 2004 2009 2006
3 1 2004 2005

4 3 2009 2015 2009 
4 2 2000 2008 2006
4 1 2000 2005
; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Rikke&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2019 18:34:25 GMT</pubDate>
    <dc:creator>RTN</dc:creator>
    <dc:date>2019-11-20T18:34:25Z</dc:date>
    <item>
      <title>Adding an observation depending on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605878#M175865</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS 9.4 and I need help in adding a new observation depending on other observations.&lt;/P&gt;&lt;P&gt;I have a data set with people with 1 or more observations. I have an ID, group, study_start, study_end, group_date. I have more variables per observation that are irrelevant here. The other variables are the same for every ID, they don't change even if it is a new observation.&lt;/P&gt;&lt;P&gt;What I want is to add an observation IF the group_date is after study_start. Then I want an observation where group is 1 and study_start is the same as the previous one and study_end is the same as the previous group-date -1. I have organized it in descending year to make it easier to add an observation. It is not so important to get the study_end;&amp;nbsp;I can manage that once I get the new observation. It is however, important that I get all my variables copied to the new observation and that the group =1.&lt;/P&gt;&lt;P&gt;Hope somebody can help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID group study_start study_end group_date;

1 1 2013 2015 2013
1 2 2000 2012 2011

2 3 2000 2015 2004

3 2 2004 2009 2006

4 3 2009 2015 2009 
4 2 2006 2008 2006

run;

data want;
input ID group study_start study_end group_date;

1 1 2013 2015 2013
1 2 2000 2012 2011
1 1 2000 2010 

2 3 2000 2015 2004
2 1 2000 2003

3 2 2004 2009 2006
3 1 2004 2005

4 3 2009 2015 2009 
4 2 2000 2008 2006
4 1 2000 2005
; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Rikke&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 18:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605878#M175865</guid>
      <dc:creator>RTN</dc:creator>
      <dc:date>2019-11-20T18:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding an observation depending on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605883#M175868</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID group study_start study_end group_date;
cards;
1 1 2013 2015 2013
1 2 2000 2012 2011
2 3 2000 2015 2004
3 2 2004 2009 2006
4 3 2009 2015 2009 
4 2 2000 2008 2006
;
run;

data want;
	set have;
	by id;

	output;

	if last.id then do;
		if  study_start &amp;lt; group_date then do;
			study_end=group_date-1;
			group_date=.;output;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 18:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605883#M175868</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-20T18:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding an observation depending on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605884#M175869</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID group study_start study_end group_date;
	datalines;
1 1 2013 2015 2013
1 2 2000 2012 2011
2 3 2000 2015 2004
3 2 2004 2009 2006
4 3 2009 2015 2009 
4 2 2006 2008 2006
;
run;

data want;
	set have;
	by id;
	output;
	if last.id then do;
		group=1;
		study_end=group_date-1;
		group_date=.;
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 18:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-an-observation-depending-on-other-observations/m-p/605884#M175869</guid>
      <dc:creator>franriv</dc:creator>
      <dc:date>2019-11-20T18:51:07Z</dc:date>
    </item>
  </channel>
</rss>

