<?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: PROC EXPAND - w/ duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486500#M126597</link>
    <description>&lt;P&gt;Would it work if you create a FREQ variable for the duplicates.&amp;nbsp; I don't have PROC EXPAND so I can't test but you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway missing;
   class grp x;
   output out=haveN(drop=_type_) idgroup(out(y)=);
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 193px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22423i7A862F03B11F39D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Aug 2018 22:30:33 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2018-08-13T22:30:33Z</dc:date>
    <item>
      <title>PROC EXPAND - w/ duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486486#M126592</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to do some simple linear interpolation (also extrapolate beyond the endpoints). I am using a simple PROC EXPAND. The problem occurs when it needs to interpolate for duplicate values. See the code below for an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Have;
INPUT Grp $ X Y;
DATALINES;
A	1	.
A	2	10
A	3	.
A	3	.
A	4	.
A	5	25
B	1	.
B	2	20
B	3	.
B	4	.
B	5	50
B	6	.
;RUN;

PROC EXPAND
DATA=Have
OUT=Want
METHOD=JOIN
EXTRAPOLATE;
ID X;
BY Grp;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since there are two X-values of 3 in group A, it gives me the following error and removes the entire group A from the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Observation with duplicate ID value found. The value of the ID variable, X=3, at
       observation number 4 in data set WORK.HAVE is the same as the previous observation.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I interpolate (and extrapolate) while keeping the duplicate values? I can't dedup, because I will later need to calculate a 1-in-200 event based on ALL of my observations, including the duplicates&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 21:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486486#M126592</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-08-13T21:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: PROC EXPAND - w/ duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486490#M126593</link>
      <description>&lt;P&gt;Can you add a small decimal amount to get the values? I believe SAS will interpret them as equally spaced though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA Have;
INPUT Grp $ X Y;
DATALINES;
A	1	.
A	2	10
A	3	.
A	3	.
A	4	.
A	5	25
B	1	.
B	2	20
B	3	.
B	4	.
B	5	50
B	6	.
;RUN;

data have;
set have;
by grp X;
if first.x then counter=0;
counter+1;
if not (first.x and last.x) then do;
x2 = x + counter/10;
end;
else x2=x;
run;


PROC EXPAND
DATA=Have
OUT=Want
METHOD=JOIN
EXTRAPOLATE;
ID X2;
BY Grp;
RUN;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210638"&gt;@SASaholic629&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to do some simple linear interpolation (also extrapolate beyond the endpoints). I am using a simple PROC EXPAND. The problem occurs when it needs to interpolate for duplicate values. See the code below for an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Have;
INPUT Grp $ X Y;
DATALINES;
A	1	.
A	2	10
A	3	.
A	3	.
A	4	.
A	5	25
B	1	.
B	2	20
B	3	.
B	4	.
B	5	50
B	6	.
;RUN;

PROC EXPAND
DATA=Have
OUT=Want
METHOD=JOIN
EXTRAPOLATE;
ID X;
BY Grp;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since there are two X-values of 3 in group A, it gives me the following error and removes the entire group A from the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Observation with duplicate ID value found. The value of the ID variable, X=3, at
       observation number 4 in data set WORK.HAVE is the same as the previous observation.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I interpolate (and extrapolate) while keeping the duplicate values? I can't dedup, because I will later need to calculate a 1-in-200 event based on ALL of my observations, including the duplicates&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 21:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486490#M126593</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-13T21:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC EXPAND - w/ duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486500#M126597</link>
      <description>&lt;P&gt;Would it work if you create a FREQ variable for the duplicates.&amp;nbsp; I don't have PROC EXPAND so I can't test but you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway missing;
   class grp x;
   output out=haveN(drop=_type_) idgroup(out(y)=);
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 193px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22423i7A862F03B11F39D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 22:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486500#M126597</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-08-13T22:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: PROC EXPAND - w/ duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486508#M126601</link>
      <description>&lt;P&gt;Use a freq variable, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Have;
INPUT Grp $ X Y;
DATALINES;
A	1	.
A	2	10
A	3	5
A	3	.
A	4	.
A	5	25
B	1	.
B	2	20
B	3	.
B	4	.
B	5	50
B	6	.
;

data want0;
do freq = 1 by 1 until(last.X);
    set have; by grp x;
    yy = coalesce(yy, y);
    end;
drop y;
run;

PROC EXPAND
DATA=Want0
OUT=Want1
METHOD=JOIN
EXTRAPOLATE;
ID X;
BY Grp;
RUN;

data want;
set want1;
y = yy;
do i = 1 to freq;
    output;
    end;
drop i yy freq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Aug 2018 22:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPAND-w-duplicates/m-p/486508#M126601</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-13T22:42:36Z</dc:date>
    </item>
  </channel>
</rss>

