<?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 run proc Expand for specific records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813578#M321123</link>
    <description>&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;It works perfectly.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2022 19:14:17 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2022-05-16T19:14:17Z</dc:date>
    <item>
      <title>How to run proc Expand for specific records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813409#M321035</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I want to run the proc expand for only date&amp;gt;=3 in the below example.&lt;/P&gt;
&lt;P&gt;I try Where but it doesn't work correctly.&lt;/P&gt;
&lt;P&gt;Can you please help?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date value;
datalines;
1 1 3
1 2 4
1 3 1
1 4 5
2 1 1
2 2 2
2 3 10
2 4 0
;run;

proc expand data=have out=temp2 METHOD=STEP;
by id ;
convert value		=SUM3/transformout=(MOVsum  3 );
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 02:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813409#M321035</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-05-16T02:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to run proc Expand for specific records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813414#M321037</link>
      <description>&lt;P&gt;If your dates are really 1, 2, 3, 4, ..., then you could use the WHERE filter on the output dataset, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc expand data=have out=temp2 (where=(date&amp;gt;=3)) METHOD=STEP;
by id ;
  convert value		=SUM3/transformout=(MOVsum 3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above will produce 4 observations in the TEMP2 dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another alternative is to keep the extra observations for the first two dates of each ID, but to set SUM3=. for those observations, via the TRIMLEFT parameter in the CONVERT statement.&amp;nbsp; Edited: removed unnecessary where filter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc expand data=have out=temp2 METHOD=STEP;
 convert value		=SUM3/transformout=(MOVsum 3 trimleft 2);
by id ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The advantage of the TRIMLEFT option is that is it telling proc expand to only generate SUM3 when the moving window has 3 non-missing values.&amp;nbsp; You will get 8 observations, 4 with SUM3=. and 4 with non-missing values of SUM3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, you could use the TRIMLEFT option, and then add a "where=(sum^=.))" filter.&amp;nbsp; This would allow you to drop the first two obs for each ID, even if different ID's had different series of DATE values - no need to know what the DATE values are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 07:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813414#M321037</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-18T07:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to run proc Expand for specific records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813578#M321123</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;It works perfectly.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 19:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813578#M321123</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-05-16T19:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to run proc Expand for specific records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813981#M321281</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;mkeintz,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Some how the Trimleft code yield the only 4 record instead of 8.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you help to fix it to make SAS keep all original records while computing the sum of only date&amp;gt;=3?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;HHC&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;316 proc expand data=have out=temp2 (where=(date&amp;gt;=3)) METHOD=STEP;&lt;BR /&gt;317 convert value =SUM3/transformout=(MOVsum 3 trimleft 2);&lt;BR /&gt;318 by id ;&lt;BR /&gt;319 run;&lt;/P&gt;
&lt;P&gt;NOTE: The data set &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;WORK.TEMP2 has 4 observations&lt;/STRONG&gt;&lt;/FONT&gt; and 5 variables.&lt;BR /&gt;NOTE: PROCEDURE EXPAND used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 03:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813981#M321281</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-05-18T03:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to run proc Expand for specific records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813998#M321296</link>
      <description>&lt;P&gt;I edited the code to drop the extraneous where filter.&amp;nbsp; Try the revised code.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 07:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-run-proc-Expand-for-specific-records/m-p/813998#M321296</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-18T07:11:41Z</dc:date>
    </item>
  </channel>
</rss>

