<?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: retain in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710024#M218476</link>
    <description>&lt;P&gt;You cannot rename a variable to the name of a variable that already exists.&lt;/P&gt;
&lt;P&gt;Which variable is the input and which is the output?&lt;/P&gt;
&lt;P&gt;Can you explain the logic of your formula?&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jan 2021 19:55:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-01-07T19:55:35Z</dc:date>
    <item>
      <title>retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710012#M218473</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I am trying to create below output for variable ADY with attached program but I got something different values. Can anyone please help on this.&lt;/P&gt;
&lt;P&gt;Required output:&lt;/P&gt;
&lt;P&gt;subjid avisit ady_orig ady&lt;BR /&gt;001 1-week 6 0&lt;BR /&gt;001 1-month 27 21&lt;BR /&gt;001 3-month 90 63 (63 = 90-21+6)&lt;BR /&gt;001 6-month 180 90 (90 = 180- 63-21+6)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Program Used:&lt;/P&gt;
&lt;P&gt;data od;&lt;BR /&gt;set od(rename=(ady = ady_orig));&lt;BR /&gt;by studyid usubjid avisitn avisit adtm ady_orig epoch alat;&lt;BR /&gt;retain ADY;&lt;BR /&gt;if first.usubjid then ADY = ADY_ORIG;&lt;BR /&gt;else ADY = ADY_ORIG - ADY;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Kumar.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710012#M218473</guid>
      <dc:creator>Kumar6</dc:creator>
      <dc:date>2021-01-07T19:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710017#M218475</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319560"&gt;@Kumar6&lt;/a&gt;&amp;nbsp; Assuming you have&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;ady_orig&amp;nbsp;&lt;/STRONG&gt; in your dataset and you want to create new variable ady, you likely want to use DIF function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;set have;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;by id;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ady=dif(ady_orig);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if first.id then ady=.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710017#M218475</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-07T19:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710024#M218476</link>
      <description>&lt;P&gt;You cannot rename a variable to the name of a variable that already exists.&lt;/P&gt;
&lt;P&gt;Which variable is the input and which is the output?&lt;/P&gt;
&lt;P&gt;Can you explain the logic of your formula?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710024#M218476</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-07T19:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710030#M218483</link>
      <description>&lt;P&gt;Be extremely cautious, as in don't do this with critical data sets until you've worked out any logic issues with a subset or&amp;nbsp; other data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This completely replaces the original Do data set if there are no syntax errors that stop the set from running.&lt;/P&gt;
&lt;P&gt;Renaming or dropping variables means that if you need to rerun the code for some reason, such as correcting a typo from + to - , can cause errors because the original data is gone and the "old" names are no longer available at that point.&lt;/P&gt;
&lt;P&gt;If you make an assignment value error but not a syntax error you no longer have the values you expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is much better until you get more experience with SAS to use a different output data set name.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 20:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710030#M218483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-07T20:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710032#M218485</link>
      <description>&lt;P&gt;I would also ask you for more information too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also please provide more data using at least two SUBJIDs.&amp;nbsp; Problems in this type of evolution are typical when 1) using lag functions and 2) data boundaries between two SUBJIDs records are crossed.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 20:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710032#M218485</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-07T20:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710042#M218488</link>
      <description>&lt;BR /&gt;I just re-framed the program and added 1 more subject. &lt;BR /&gt;Thank You for your time on this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Required output:&lt;BR /&gt;subjid avisit    ady    ady_mod&lt;BR /&gt;001 1-week        6     6&lt;BR /&gt;001 1-month      27     21&lt;BR /&gt;001 3-month      90     63 (63 = 90-21+6)&lt;BR /&gt;001 6-month      180    90 (90 = 180- 63-21+6)&lt;BR /&gt;&lt;BR /&gt;002 1-week        8     8&lt;BR /&gt;002 1-month      36     28(28= 36-8)&lt;BR /&gt;002 3-month      94     58(58=94-36+8)&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;Program Used:&lt;BR /&gt;&lt;BR /&gt;data od;&lt;BR /&gt;set od;&lt;BR /&gt;by studyid usubjid avisitn avisit adtm ady epoch alat;&lt;BR /&gt;retain ADY_mod;&lt;BR /&gt;if first.usubjid then ADY_mod = ADY;&lt;BR /&gt;else ADY_mod = ADY - ADY_mod;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 07 Jan 2021 20:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710042#M218488</guid>
      <dc:creator>Kumar6</dc:creator>
      <dc:date>2021-01-07T20:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710043#M218489</link>
      <description>Sure, Thanks for your advice.&lt;BR /&gt;&lt;BR /&gt;I just re-framed the program and added 1 more subject. &lt;BR /&gt;&lt;BR /&gt;Required output:&lt;BR /&gt;subjid avisit    ady    ady_mod&lt;BR /&gt;001 1-week        6     6&lt;BR /&gt;001 1-month      27     21&lt;BR /&gt;001 3-month      90     63 (63 = 90-21+6)&lt;BR /&gt;001 6-month      180    90 (90 = 180- 63-21+6)&lt;BR /&gt;&lt;BR /&gt;002 1-week        8     8&lt;BR /&gt;002 1-month      36     28(28= 36-8)&lt;BR /&gt;002 3-month      94     58(58=94-36+8)&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;Program Used:&lt;BR /&gt;&lt;BR /&gt;data od;&lt;BR /&gt;set od;&lt;BR /&gt;by studyid usubjid avisitn avisit adtm ady epoch alat;&lt;BR /&gt;retain ADY_mod;&lt;BR /&gt;if first.usubjid then ADY_mod = ADY;&lt;BR /&gt;else ADY_mod = ADY - ADY_mod;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 07 Jan 2021 20:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain/m-p/710043#M218489</guid>
      <dc:creator>Kumar6</dc:creator>
      <dc:date>2021-01-07T20:39:55Z</dc:date>
    </item>
  </channel>
</rss>

