<?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 a column with post values for same person in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943680#M369841</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It is much easier to remember something than to predict the future.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I do not agree with this premise.&amp;nbsp; The following does not require a preliminary descending sort (and possibly a posterior ascending sort for later data management or analysis).&amp;nbsp; It's a couple extra lines beyond the call to a LAG function but is still pretty easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input study_id	year_for_score	score;
datalines;
175004173018	2003	4.5
175004173018	2004	4.5
175004173018	2005	6.5
175004173018	2006	6.5
175102254399	2000	8
175102254399	2001	8
175299202118	1996	5.5
175299202118	1997	5.5
run;

data want;
  set have (keep=study_id);
  by study_id;
  merge have 
        have (firstobs=2 keep=score rename=(score=next_score));
  if last.study_id then call missing(next_score);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Sep 2024 17:29:15 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-09-12T17:29:15Z</dc:date>
    <item>
      <title>how to add a column with post values for same person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943505#M369784</link>
      <description>&lt;P&gt;I have a dataset like below. I need to calculate the difference between the previous and next score.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;study_id	year_for_score	score
175004173018	2003	4.5
175004173018	2004	4.5
175004173018	2005	6.5
175004173018	2006	6.5
175102254399	2000	8
175102254399	2001	8
175299202118	1996	5.5
175299202118	1997	5.5
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I create a column like below "score_next"?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;study_id	year_for_score	score	score_next
175004173018	2003	4.5	       4.5
175004173018	2004	4.5	       6.5
175004173018	2005	6.5	       6.5
175004173018	2006	6.5	        .
175102254399	2000	8	       8
175102254399	2001	8	       .
175299202118	1996	5.5    	5.5
175299202118	1997	5.5	        .
&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2024 15:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943505#M369784</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2024-09-11T15:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a column with post values for same person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943514#M369790</link>
      <description>&lt;P&gt;It is much easier to remember something than to predict the future.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=HAVE;
  by study_id descending year_for_score;
run;
data WANT;
  set HAVE;
  by study_id;
  score_next=lag(score);
&amp;nbsp;&amp;nbsp;if&amp;nbsp;first.study_id&amp;nbsp;then&amp;nbsp;call&amp;nbsp;missing(score_next);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2024 15:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943514#M369790</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-11T15:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a column with post values for same person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943680#M369841</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It is much easier to remember something than to predict the future.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I do not agree with this premise.&amp;nbsp; The following does not require a preliminary descending sort (and possibly a posterior ascending sort for later data management or analysis).&amp;nbsp; It's a couple extra lines beyond the call to a LAG function but is still pretty easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input study_id	year_for_score	score;
datalines;
175004173018	2003	4.5
175004173018	2004	4.5
175004173018	2005	6.5
175004173018	2006	6.5
175102254399	2000	8
175102254399	2001	8
175299202118	1996	5.5
175299202118	1997	5.5
run;

data want;
  set have (keep=study_id);
  by study_id;
  merge have 
        have (firstobs=2 keep=score rename=(score=next_score));
  if last.study_id then call missing(next_score);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2024 17:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-column-with-post-values-for-same-person/m-p/943680#M369841</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-09-12T17:29:15Z</dc:date>
    </item>
  </channel>
</rss>

