<?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: Reshape long data into wide data with lag in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238987#M55464</link>
    <description>&lt;P&gt;thank you very much ,but don't as I want, i have try ,and there 16 &amp;nbsp;ships, i just show some part of the data.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2015 20:15:34 GMT</pubDate>
    <dc:creator>MMTG</dc:creator>
    <dc:date>2015-12-11T20:15:34Z</dc:date>
    <item>
      <title>Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238977#M55462</link>
      <description>&lt;P&gt;I have some data, I want reshape long to wide, but with lag;&lt;/P&gt;&lt;P&gt;have like this ;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1155i48C77BB9F10B97E1/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="QQ截图20151211203327.jpg" title="QQ截图20151211203327.jpg" /&gt;&lt;/P&gt;&lt;P&gt;want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first var is&amp;nbsp;Turnover,&lt;/P&gt;&lt;P&gt;second is month,&lt;/P&gt;&lt;P&gt;jour is day in the month,&lt;/P&gt;&lt;P&gt;an is year,&lt;/P&gt;&lt;P&gt;ident_num is the id of ship( there are 16ships),&lt;/P&gt;&lt;P&gt;ident_temp(1 is the first day record the obs,2 is the second,)&lt;/P&gt;&lt;P&gt;semaine_num (1 is monday， 2 is Tuesday,&amp;nbsp;There si no Sunday, only Monday to&amp;nbsp;Saturday data).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 21:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238977#M55462</guid>
      <dc:creator>MMTG</dc:creator>
      <dc:date>2015-12-11T21:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238984#M55463</link>
      <description>&lt;P&gt;There is most likely a more elegent way to do this without the sorts but here is a solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;infile cards dsd dlm= ' ';&lt;BR /&gt;input ca mois jour an ident_num ident_temp semain_num;&lt;BR /&gt;cards;&lt;BR /&gt;2427.93 1 3 2002 1 1 4&lt;BR /&gt;2284.22 1 4 2002 1 2 5&lt;BR /&gt;2544.94 1 5 2002 1 3 6&lt;BR /&gt;2055.43 1 7 2002 1 4 1&lt;BR /&gt;2247.45 1 8 2002 1 5 2&lt;BR /&gt;2891.51 1 9 2002 1 6 3&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc sort data=have;by descending ident_temp;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;lag1=lag1(ca);&lt;BR /&gt;lag2=lag2(ca);&lt;BR /&gt;lag3=lag3(ca);&lt;BR /&gt;lag4=lag4(ca);&lt;BR /&gt;lag5=lag5(ca);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=want;by ident_temp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 20:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238984#M55463</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-12-11T20:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238987#M55464</link>
      <description>&lt;P&gt;thank you very much ,but don't as I want, i have try ,and there 16 &amp;nbsp;ships, i just show some part of the data.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 20:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238987#M55464</guid>
      <dc:creator>MMTG</dc:creator>
      <dc:date>2015-12-11T20:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238991#M55465</link>
      <description>Please post your data in the format that Steelers has posted, when you post pictures, someone has to type in the data to generate sample data to help you solve your problem. Also, please do take the time to clearly illustrate your problem and why a solution doesn't work. You're not clear above. All of the above is intended so that you can get help faster...</description>
      <pubDate>Fri, 11 Dec 2015 20:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238991#M55465</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-11T20:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238993#M55466</link>
      <description>&lt;P&gt;I HAVED POSTED THE DATA NOW&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 20:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238993#M55466</guid>
      <dc:creator>MMTG</dc:creator>
      <dc:date>2015-12-11T20:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238995#M55467</link>
      <description>&lt;P&gt;I assume you don't want to mix data from different ships. It can be done in one step with random access (point=)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have nobs=limit;
array lag{5};
do i = 1 to dim(lag);
    fetch = _n_ + i;
    if fetch &amp;lt;= limit then do;
        set have(keep=ca ident_num rename=(ident_num=other_num ca=other_ca)) point=fetch;
        if other_num = ident_num then lag{i} = other_ca;
        end;
    end;
drop i fetch other_num other_ca;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Dec 2015 20:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238995#M55467</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-11T20:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238996#M55468</link>
      <description>&lt;P&gt;I'm still not clear what you want.&amp;nbsp; I think you are saying you want 16 new variables.&amp;nbsp; If that is the case this is a solution.&amp;nbsp; Still has the two sorts in it which I'd like to work around:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile cards dsd;&lt;BR /&gt;input ca mois jour an ident_num ident_temp semain_num;&lt;BR /&gt;cards;&lt;BR /&gt;2427.93,1,3,2002,1,1,4&lt;BR /&gt;2284.22,1,4,2002,1,2,5&lt;BR /&gt;2544.94,1,5,2002,1,3,6&lt;BR /&gt;2055.43,1,7,2002,1,4,1&lt;BR /&gt;2247.45,1,8,2002,1,5,2&lt;BR /&gt;2891.51,1,9,2002,1,6,3&lt;BR /&gt;2571.43,1,10,2002,1,7,4&lt;BR /&gt;2646.82,1,11,2002,1,8,5&lt;BR /&gt;3096.43,1,12,2002,1,9,6&lt;BR /&gt;2173.95,1,14,2002,1,10,1&lt;BR /&gt;2243.97,1,15,2002,1,11,2&lt;BR /&gt;2304.2,1,16,2002,1,12,3&lt;BR /&gt;2388.01,1,17,2002,1,13,4&lt;BR /&gt;2435.16,1,18,2002,1,14,5&lt;BR /&gt;2593.02,1,19,2002,1,15,6&lt;BR /&gt;2012.54,1,21,2002,1,16,1&lt;BR /&gt;2223.43,1,22,2002,1,17,2&lt;BR /&gt;2086.49,1,23,2002,1,18,3&lt;BR /&gt;2342.84,1,24,2002,1,19,4&lt;BR /&gt;2180.02,1,25,2002,1,20,5&lt;BR /&gt;2120.58,1,26,2002,1,21,6&lt;BR /&gt;1943.99,1,28,2002,1,22,1&lt;BR /&gt;2169.63,1,29,2002,1,23,2&lt;BR /&gt;2197.35,1,30,2002,1,24,3&lt;BR /&gt;2006.92,1,31,2002,1,25,4&lt;BR /&gt;2310.02,2,1,2002,1,26,5&lt;BR /&gt;2126.89,2,2,2002,1,27,6&lt;BR /&gt;2077.39,2,4,2002,1,28,1&lt;BR /&gt;1928.1,2,5,2002,1,29,2&lt;BR /&gt;2098.27,2,6,2002,1,30,3&lt;BR /&gt;2199.86,2,7,2002,1,31,4&lt;BR /&gt;2355.6,2,8,2002,1,32,5&lt;BR /&gt;1950.73,2,9,2002,1,33,6&lt;BR /&gt;2118.97,2,11,2002,1,34,1&lt;BR /&gt;2348.87,2,12,2002,1,35,2&lt;BR /&gt;2443.23,2,13,2002,1,36,3&lt;BR /&gt;2602.99,2,14,2002,1,37,4&lt;BR /&gt;2162.27,2,15,2002,1,38,5&lt;BR /&gt;1927.4,2,16,2002,1,39,6&lt;BR /&gt;1964.16,2,18,2002,1,40,1&lt;BR /&gt;2175.51,2,19,2002,1,41,2&lt;BR /&gt;2194.22,2,20,2002,1,42,3&lt;BR /&gt;2296.39,2,21,2002,1,43,4&lt;BR /&gt;2200.81,2,22,2002,1,44,5&lt;BR /&gt;2005.12,2,23,2002,1,45,6&lt;BR /&gt;1967.49,2,25,2002,1,46,1&lt;BR /&gt;2125.22,2,26,2002,1,47,2&lt;BR /&gt;2087.93,2,27,2002,1,48,3&lt;BR /&gt;2093.22,2,28,2002,1,49,4&lt;BR /&gt;2245.66,3,1,2002,1,50,5&lt;BR /&gt;2444.07,3,2,2002,1,51,6&lt;BR /&gt;2158.51,3,4,2002,1,52,1&lt;BR /&gt;2074.35,3,5,2002,1,53,2&lt;BR /&gt;2052.68,3,6,2002,1,54,3&lt;BR /&gt;2393.61,3,7,2002,1,55,4&lt;BR /&gt;2407.32,3,8,2002,1,56,5&lt;BR /&gt;2267.7,3,9,2002,1,57,6&lt;BR /&gt;2166.9,3,11,2002,1,58,1&lt;BR /&gt;2266.97,3,12,2002,1,59,2&lt;BR /&gt;2317.02,3,13,2002,1,60,3&lt;BR /&gt;2191.15,3,14,2002,1,61,4&lt;BR /&gt;2387.77,3,15,2002,1,62,5&lt;BR /&gt;2432.63,3,16,2002,1,63,6&lt;BR /&gt;2096.73,3,18,2002,1,64,1&lt;BR /&gt;2088.37,3,19,2002,1,65,2&lt;BR /&gt;2185.96,3,20,2002,1,66,3&lt;BR /&gt;2419.34,3,21,2002,1,67,4&lt;BR /&gt;2548.06,3,22,2002,1,68,5&lt;BR /&gt;2056.63,3,23,2002,1,69,6&lt;BR /&gt;2105.71,3,25,2002,1,70,1&lt;BR /&gt;2082.3,3,26,2002,1,71,2&lt;BR /&gt;2353.34,3,27,2002,1,72,3&lt;BR /&gt;2475.71,3,28,2002,1,73,4&lt;BR /&gt;2224.62,3,30,2002,1,74,6&lt;BR /&gt;2348.35,4,2,2002,1,75,2&lt;BR /&gt;2349.47,4,3,2002,1,76,3&lt;BR /&gt;2376.97,4,4,2002,1,77,4&lt;BR /&gt;2169.63,4,5,2002,1,78,5&lt;BR /&gt;2344.63,4,6,2002,1,79,6&lt;BR /&gt;2047.11,4,8,2002,1,80,1&lt;BR /&gt;2273.1,4,9,2002,1,81,2&lt;BR /&gt;2134.35,4,10,2002,1,82,3&lt;BR /&gt;2043.25,4,11,2002,1,83,4&lt;BR /&gt;2189.95,4,12,2002,1,84,5&lt;BR /&gt;1969.94,4,13,2002,1,85,6&lt;BR /&gt;2106.33,4,15,2002,1,86,1&lt;BR /&gt;2292.86,4,16,2002,1,87,2&lt;BR /&gt;2440.9,4,17,2002,1,88,3&lt;BR /&gt;2374.14,4,18,2002,1,89,4&lt;BR /&gt;2364.45,4,19,2002,1,90,5&lt;BR /&gt;2052.59,4,20,2002,1,91,6&lt;BR /&gt;2021.61,4,22,2002,1,92,1&lt;BR /&gt;2193.04,4,23,2002,1,93,2&lt;BR /&gt;2286.61,4,24,2002,1,94,3&lt;BR /&gt;2299.07,4,25,2002,1,95,4&lt;BR /&gt;2139.42,4,26,2002,1,96,5&lt;BR /&gt;2120.9,4,27,2002,1,97,6&lt;BR /&gt;1894.11,4,29,2002,1,98,1&lt;BR /&gt;2089.68,4,30,2002,1,99,2&lt;BR /&gt;2424.98,5,2,2002,1,100,4&lt;BR /&gt;2418.49,5,3,2002,1,101,5&lt;BR /&gt;2181.87,5,4,2002,1,102,6&lt;BR /&gt;2139.99,5,6,2002,1,103,1&lt;BR /&gt;2329.11,5,7,2002,1,104,2&lt;BR /&gt;2275.18,5,10,2002,1,105,5&lt;BR /&gt;1921.58,5,11,2002,1,106,6&lt;BR /&gt;1979.94,5,13,2002,1,107,1&lt;BR /&gt;2076.57,5,14,2002,1,108,2&lt;BR /&gt;2288.07,5,15,2002,1,109,3&lt;BR /&gt;2464.58,5,16,2002,1,110,4&lt;BR /&gt;2064.54,5,17,2002,1,111,5&lt;BR /&gt;2117.22,5,18,2002,1,112,6&lt;BR /&gt;2179.8,5,21,2002,1,113,2&lt;BR /&gt;2029.69,5,22,2002,1,114,3&lt;BR /&gt;2259.05,5,23,2002,1,115,4&lt;BR /&gt;2390.29,5,24,2002,1,116,5&lt;BR /&gt;2092.5,5,25,2002,1,117,6&lt;BR /&gt;2021.46,5,27,2002,1,118,1&lt;BR /&gt;2218.12,5,28,2002,1,119,2&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc sort data=have;by descending ident_temp;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;%macro lag;&lt;BR /&gt;%do i = 1 %to 16;&lt;BR /&gt;lag&amp;amp;i=lag&amp;amp;i(ca);&lt;BR /&gt;%end;&lt;BR /&gt;%mend lag;&lt;BR /&gt;%lag;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=want;by ident_temp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 20:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/238996#M55468</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-12-11T20:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape long data into wide data with lag</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/239002#M55469</link>
      <description>&lt;P&gt;Since the records start with semaine_num&amp;nbsp;=4 i think lag variables should be missing for semaine_num =3 instead of semaine_num =2. Can you confirm?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 21:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reshape-long-data-into-wide-data-with-lag/m-p/239002#M55469</guid>
      <dc:creator>ndp</dc:creator>
      <dc:date>2015-12-11T21:28:37Z</dc:date>
    </item>
  </channel>
</rss>

