<?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: first./last./retain in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745740#M233825</link>
    <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289881"&gt;@Aku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please consider that Y is a test variable, instead of Y in my real dataset I have dates.&lt;BR /&gt;I can't apply your solution.&lt;/P&gt;&lt;P&gt;I need data driven solution here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Artur&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jun 2021 11:52:06 GMT</pubDate>
    <dc:creator>webart999ARM</dc:creator>
    <dc:date>2021-06-04T11:52:06Z</dc:date>
    <item>
      <title>first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745732#M233820</link>
      <description>&lt;P&gt;Good afternoon community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one small simple question for which I would like to ask you for some efficient solutions.&lt;BR /&gt;&lt;BR /&gt;I have the below dataset.&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="webart999ARM_0-1622806384408.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60017i42379F5A1FCB613F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="webart999ARM_0-1622806384408.png" alt="webart999ARM_0-1622806384408.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to derive new variable Z, which will have unique values for each unique Y variable value(marked with red).&lt;/P&gt;&lt;P&gt;It seems pretty simple but I am struggling to find any effective solution.&lt;BR /&gt;I just don't want to use nodupkey/merge back solution which is pretty straightforward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;BR /&gt;Artur&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 11:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745732#M233820</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T11:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745739#M233824</link>
      <description>&lt;P&gt;I made z based on y but you can define something other if needed.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Data want;&lt;BR /&gt;set have;&lt;BR /&gt;by x y notsorted;&lt;BR /&gt;Retain z 0;&lt;BR /&gt;if First.y then z = y/100;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 11:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745739#M233824</guid>
      <dc:creator>Aku</dc:creator>
      <dc:date>2021-06-04T11:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745740#M233825</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289881"&gt;@Aku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please consider that Y is a test variable, instead of Y in my real dataset I have dates.&lt;BR /&gt;I can't apply your solution.&lt;/P&gt;&lt;P&gt;I need data driven solution here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Artur&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 11:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745740#M233825</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T11:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745742#M233827</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268199"&gt;@webart999ARM&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This example can be interpreted in a number of ways, and I can think of several interpretations of your example, that each would require different programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, please clarify: do you obtain the new column as:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;y/100&lt;/LI&gt;
&lt;LI&gt;group sequence, each time Y changes the new column is incremented by 1 (even if Y changes by something other than the 100 shown)&lt;/LI&gt;
&lt;LI&gt;something else&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Then you say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Please consider that Y is a test variable, instead of Y in my real dataset I have dates.&lt;BR /&gt;I can't apply your solution.&lt;/P&gt;
&lt;P&gt;I need data driven solution here.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide a more meaningful set of data that is representative of your actual problem. And also please explain how the new variable is computed. Please don't make us guess or try to figure this out, by ourselves, how the new variable is created. Explain it clearly. As you can see, we can't figure it out from what you have presented.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745742#M233827</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-04T12:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745747#M233831</link>
      <description>&lt;P&gt;Dear,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see from my reply above.&lt;BR /&gt;Y is a fake variable here, instead of it I have dates in numerical representation.&lt;BR /&gt;E.g.&lt;/P&gt;&lt;P&gt;01JAN1996&lt;/P&gt;&lt;P&gt;01JAN1996&lt;/P&gt;&lt;P&gt;01JAN1996&lt;/P&gt;&lt;P&gt;02JAN1996&lt;/P&gt;&lt;P&gt;02JAN1996&lt;/P&gt;&lt;P&gt;02JAN1996&lt;/P&gt;&lt;P&gt;03JAN1996&lt;/P&gt;&lt;P&gt;03JAN1996&lt;/P&gt;&lt;P&gt;03JAN1996&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to derive Z variable, which will have(in this example) 3 different values, 1, 2 and 3 accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Artur&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745747#M233831</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T12:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745748#M233832</link>
      <description>&lt;P&gt;Sounds like you want simple counter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  by x y ;
  z + first.y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: The new variable Z cannot already exist in the input dataset HAVE.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745748#M233832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-04T12:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745749#M233833</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268199"&gt;@webart999ARM&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide a complete example, showing the inputs and the desired outputs. As I said, don't make us guess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain clearly how the outputs are derived from the inputs. As I said, don't make us guess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745749#M233833</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-04T12:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745750#M233834</link>
      <description>Sorry but I can't explain it in more details.&lt;BR /&gt;&lt;BR /&gt;New variable is NOT computed yet.&lt;BR /&gt;If I knew how it should be computed then I would not post this question here.</description>
      <pubDate>Fri, 04 Jun 2021 12:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745750#M233834</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T12:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745751#M233835</link>
      <description>&lt;P&gt;In addition to what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;said, post your example data in usable form (as code, in a DATA step with DATALINES), so we instantly have something to test code against. We cannot test code with pictures.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745751#M233835</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-04T12:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745753#M233836</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268199"&gt;@webart999ARM&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry but I can't explain it in more details.&lt;BR /&gt;&lt;BR /&gt;New variable is NOT computed yet.&lt;BR /&gt;If I knew how it should be computed then I would not post this question here.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm not asking you for SAS code, I am asking for an explanation, I want you to explain what you want and how you do it in words, as if you were talking to your professor or to your boss.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745753#M233836</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-04T12:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745754#M233837</link>
      <description>&lt;P&gt;Looks like you need this (using variable names from your initial post):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by x y;
if first.x
then z = 1;
else if first.y then z + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745754#M233837</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-04T12:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745755#M233838</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your suggested method.&lt;/P&gt;&lt;P&gt;That's what I want to get.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solution is not quite clear for me, because I used to methods like first., last., retain, for this kind of tasks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please explain in two wards how this works, I mean the part &lt;STRONG&gt;z+first.y&lt;/STRONG&gt; ?&lt;BR /&gt;&lt;BR /&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Artur&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745755#M233838</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T12:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745759#M233840</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;for your suggested methods, that's exactly what I want.&lt;/P&gt;
&lt;P&gt;To be honest I don't understand actually how it works without retain statement. If you could explain that would be great, if no then I will try to investigate myself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is pretty simple and I thought it doesn't necessary to provide details like you asked me.&lt;BR /&gt;Sorry for not being too clear.&lt;BR /&gt;&lt;BR /&gt;Thank you again for your prompt answers and efficient solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards&lt;BR /&gt;Artur&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745759#M233840</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T12:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745765#M233841</link>
      <description>&lt;P&gt;This is a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1dfiqj146yi2cn1maeju9wo7ijs.htm" target="_self"&gt;SUM statement&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS evaluates boolean expressions to 1 (TRUE) or 0 (FALSE).&amp;nbsp; So when FIRST.Y is TRUE it has a value of 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when this observation is the first one with this value of Y (within the current value of X) the counter is incremented by 1.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745765#M233841</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-04T12:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: first./last./retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745772#M233845</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will definitely include this kind of solutions in my daily routine work.&lt;BR /&gt;Kind Regards&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Artur&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 12:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-last-retain/m-p/745772#M233845</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2021-06-04T12:44:43Z</dc:date>
    </item>
  </channel>
</rss>

