<?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 Not Sure how To Format into Longitudinal Dataset for ML in SAS Academy for Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536169#M251</link>
    <description>&lt;P&gt;So basically I want to use the prior and prior prior values as my features for my label which is the same value, y. I've changed the data into what I think is easiest to understand. I done something like this in Python, but not sure how to in SAS. Any code on how to change the have dataset into the want dataset would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input id $ y year 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,20,2016&lt;BR /&gt;1,10,2015&lt;BR /&gt;1,5,2014&lt;BR /&gt;2,60,2016&lt;BR /&gt;2,30,2015&lt;BR /&gt;2,15,2014&lt;BR /&gt;3,36,2016&lt;BR /&gt;3,18,2015&lt;BR /&gt;3,9,2014&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input id $ y year lag_1_y lag_2_y 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,20,2016,10,5&lt;BR /&gt;1,10,2015,5,.&lt;BR /&gt;1,5,2015,.,.&lt;BR /&gt;2,60,2016,30,15&lt;BR /&gt;2,30,2015,15,.&lt;BR /&gt;2,15,2014,.,.&lt;BR /&gt;3,36,2016,18,9&lt;BR /&gt;3,18,2015,9,.&lt;BR /&gt;3,9,2014,.,.&lt;BR /&gt;;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Feb 2019 16:13:41 GMT</pubDate>
    <dc:creator>krueg314</dc:creator>
    <dc:date>2019-02-16T16:13:41Z</dc:date>
    <item>
      <title>Not Sure how To Format into Longitudinal Dataset for ML</title>
      <link>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536169#M251</link>
      <description>&lt;P&gt;So basically I want to use the prior and prior prior values as my features for my label which is the same value, y. I've changed the data into what I think is easiest to understand. I done something like this in Python, but not sure how to in SAS. Any code on how to change the have dataset into the want dataset would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input id $ y year 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,20,2016&lt;BR /&gt;1,10,2015&lt;BR /&gt;1,5,2014&lt;BR /&gt;2,60,2016&lt;BR /&gt;2,30,2015&lt;BR /&gt;2,15,2014&lt;BR /&gt;3,36,2016&lt;BR /&gt;3,18,2015&lt;BR /&gt;3,9,2014&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input id $ y year lag_1_y lag_2_y 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,20,2016,10,5&lt;BR /&gt;1,10,2015,5,.&lt;BR /&gt;1,5,2015,.,.&lt;BR /&gt;2,60,2016,30,15&lt;BR /&gt;2,30,2015,15,.&lt;BR /&gt;2,15,2014,.,.&lt;BR /&gt;3,36,2016,18,9&lt;BR /&gt;3,18,2015,9,.&lt;BR /&gt;3,9,2014,.,.&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Feb 2019 16:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536169#M251</guid>
      <dc:creator>krueg314</dc:creator>
      <dc:date>2019-02-16T16:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Not Sure how To Format into Longitudinal Dataset for ML</title>
      <link>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536176#M252</link>
      <description>&lt;P&gt;You can use the lag functions, but of course you don't want to contaminate the start of any ID with lagged values of Y from the prior ID.&amp;nbsp; You can do this by examining the corresponding lagged values of ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=',';
input id $ y year 8.;
datalines;
1,20,2016
1,10,2015
1,5,2014
2,60,2016
2,30,2015
2,15,2014
3,36,2016
3,18,2015
3,9,2014
run;
data want;
  set have;
  lag_1_y=lag(y);
  if lag(id)^=id then lag_1_y=.;
  lag_2_y=lag2(y);
  if lag2(id)^=id then lag_2_y=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Feb 2019 18:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536176#M252</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-16T18:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Not Sure how To Format into Longitudinal Dataset for ML</title>
      <link>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536177#M253</link>
      <description>LAG() and LAG2() functions. &lt;BR /&gt;Remember to reset the lag values at the new ID. &lt;BR /&gt;</description>
      <pubDate>Sat, 16 Feb 2019 18:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536177#M253</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-16T18:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Not Sure how To Format into Longitudinal Dataset for ML</title>
      <link>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536442#M254</link>
      <description>&lt;P&gt;That is not called LAG, should call NEXT or FORWARD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=',';
input id $ y year 8.;
datalines;
1,20,2016
1,10,2015
1,5,2014
2,60,2016
2,30,2015
2,15,2014
3,36,2016
3,18,2015
3,9,2014
run;
data want;
  merge have
  have(firstobs=2 keep=id y rename=(id=id1 y=lag_1_y))
  have(firstobs=3 keep=id y rename=(id=id2 y=lag_2_y));
  if id ne id1 then call missing(lag_1_y);
  if id ne id2 then call missing(lag_2_y);
  drop id1 id2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Feb 2019 11:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536442#M254</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-02-18T11:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Not Sure how To Format into Longitudinal Dataset for ML</title>
      <link>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536890#M255</link>
      <description>&lt;P&gt;I changed it a little for it to work as time series needs to be descending, but it worked after adding this before your code since order doesn't matter to me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sort data=have;&lt;BR /&gt;     by descending id year;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Feb 2019 19:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Academy-for-Data-Science/Not-Sure-how-To-Format-into-Longitudinal-Dataset-for-ML/m-p/536890#M255</guid>
      <dc:creator>krueg314</dc:creator>
      <dc:date>2019-02-19T19:59:34Z</dc:date>
    </item>
  </channel>
</rss>

