<?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 change duplicate rows to another unique rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549492#M152482</link>
    <description>&lt;P&gt;Please &lt;STRONG&gt;DO NOT&lt;/STRONG&gt; post data as pictures. Nobody here likes to waste time tediously typing things off a screesnshot and correcting typos all the time.&lt;/P&gt;
&lt;P&gt;Always post SAS datasets as data steps with datalines, so we can create an &lt;EM&gt;exact&lt;/EM&gt; replica of your dataset (inlcuding all lengths, formats, etc.) for testing.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2019 05:55:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-04-09T05:55:56Z</dc:date>
    <item>
      <title>How to change duplicate rows to another unique rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549486#M152479</link>
      <description>&lt;P&gt;Hi, I hope I would not confuse those without domain knowledge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to bootstrap 100 data sets with replacement and fit a random effect model in each bootstrap sample.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the data set I would use to resample, each unique "study_id" represent a subject, each subject have 8 records("quarter").&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28537i044AA3F2B1BE2578/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I use proc surveyselect&amp;nbsp;and specify&amp;nbsp;the sample unique = "study_id"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let NumSamples = 10;       /* number of bootstrap resamples */
/* 2. Generate many bootstrap samples */
proc surveyselect data=origin seed=345
     out=Bootsample1(rename=(Replicate=SampleID))
     method=urs              /* resample with replacement */
     samprate=1              /* each bootstrap sample has N observations */
      OUTHITS                /* option to suppress the frequency var */
     reps=&amp;amp;NumSamples;       /* generate NumSamples bootstrap resamples 426*/
	samplingunit study_id;
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;After resampling, we see that study_id 10000 was selected twice, he has 2*8=16 observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28538i4B7925CD4AB08218/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final step is to fit a random effect model with a random intercept for each study_id, which require to specify the cluster variables, It requires study_id 10000 was account as two subjects with the same 8 observations and sample results, rather than one subjects with 16 observations. For example, treat the second 8-duplicate-records of "study_id" 10000 as another different "study_id" 10000A and keep the first "study_id" 10000 then we have two study_id 10000 and 10000A that have same observations and same results.&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;proc glimmix data=zheng_no0  method=quad(qpoints=10);  /*edcn  all factors latent class risk_score*/
	class study_id pred3class(ref='2')  gender age_cat(ref='1') ge_12mo_flag(ref='0');
	effect spl = spline(log_risk/naturalcubic degree=3 knotmethod=percentiles(3));
	model pct_sum = pred3class gender age_cat spl ge_12mo_flag/link=log s dist=poisson offset=logt;
	random int / subject=study_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way I could just change the study_id? Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 05:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549486#M152479</guid>
      <dc:creator>ZZ_Zheng</dc:creator>
      <dc:date>2019-04-09T05:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duplicate rows to another unique rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549490#M152480</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 563px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28539iB4EFAABABD1A6865/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;s&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the original data set used to resample, resample unit is the study_id, or resample a cluster of 8 observations of sample study_id. Thanks!!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 05:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549490#M152480</guid>
      <dc:creator>ZZ_Zheng</dc:creator>
      <dc:date>2019-04-09T05:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duplicate rows to another unique rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549492#M152482</link>
      <description>&lt;P&gt;Please &lt;STRONG&gt;DO NOT&lt;/STRONG&gt; post data as pictures. Nobody here likes to waste time tediously typing things off a screesnshot and correcting typos all the time.&lt;/P&gt;
&lt;P&gt;Always post SAS datasets as data steps with datalines, so we can create an &lt;EM&gt;exact&lt;/EM&gt; replica of your dataset (inlcuding all lengths, formats, etc.) for testing.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 05:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549492#M152482</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-09T05:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duplicate rows to another unique rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549494#M152483</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data origin;
length study_id $10;
input study_id quarter;
datalines;
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
100 1
100 2
100 3
100 4
100 5
100 6
100 7
100 8
1000 1
1000 2
1000 3
1000 4
1000 5
1000 6
1000 7
1000 8
1001 1
1001 2
1001 3
1001 4
1001 5
1001 6
1001 7
1001 8
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;and @All. Sorry, I should create a simple sample data, my raw data is large and credential and I using sas&amp;nbsp;enterprise under the off-line system. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 06:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549494#M152483</guid>
      <dc:creator>ZZ_Zheng</dc:creator>
      <dc:date>2019-04-09T06:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duplicate rows to another unique rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549544#M152500</link>
      <description>&lt;P&gt;Add a data step that manipulates study_id. Since quarter is sorted in ascending order, we can use it to detect when a second hit starts:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data origin;
length study_id $10;
input study_id quarter;
datalines;
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
100 1
100 2
100 3
100 4
100 5
100 6
100 7
100 8
1000 1
1000 2
1000 3
1000 4
1000 5
1000 6
1000 7
1000 8
1001 1
1001 2
1001 3
1001 4
1001 5
1001 6
1001 7
1001 8
;
run;
%let NumSamples = 10;       /* number of bootstrap resamples */
/* 2. Generate many bootstrap samples */
proc surveyselect data=origin seed=345
     out=Bootsample1(rename=(Replicate=SampleID))
     method=urs              /* resample with replacement */
     samprate=1              /* each bootstrap sample has N observations */
      OUTHITS                /* option to suppress the frequency var */
     reps=&amp;amp;NumSamples;       /* generate NumSamples bootstrap resamples 426*/
	samplingunit study_id;
run;

data bootsample1_a;
set bootsample1;
retain addstring ' abcdefghij';
by sampleid study_id;
l_q = lag(quarter);
if first.study_id
then i = 1;
else if l_q &amp;gt; quarter then i + 1;
study_id = cats(study_id,substr(addstring,i,1));
drop addstring i l_q;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Partial output:&lt;/P&gt;
&lt;PRE&gt; 9        1        100          1          3
10        1        100          2          3
11        1        100          3          3
12        1        100          4          3
13        1        100          5          3
14        1        100          6          3
15        1        100          7          3
16        1        100          8          3
17        1        100a         1          3
18        1        100a         2          3
19        1        100a         3          3
20        1        100a         4          3
21        1        100a         5          3
22        1        100a         6          3
23        1        100a         7          3
24        1        100a         8          3
25        1        100b         1          3
26        1        100b         2          3
27        1        100b         3          3
28        1        100b         4          3
29        1        100b         5          3
30        1        100b         6          3
31        1        100b         7          3
32        1        100b         8          3
&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 11:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549544#M152500</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-09T11:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duplicate rows to another unique rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549729#M152588</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;. Thanks!</description>
      <pubDate>Tue, 09 Apr 2019 17:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-duplicate-rows-to-another-unique-rows/m-p/549729#M152588</guid>
      <dc:creator>ZZ_Zheng</dc:creator>
      <dc:date>2019-04-09T17:55:05Z</dc:date>
    </item>
  </channel>
</rss>

