<?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: identify various observations for same variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420644#M280669</link>
    <description>Thanks for your advice. I wasn't getting anywhere with my codes so I knew&lt;BR /&gt;my codes were wrong. But as you mentioned it would be good to know where I&lt;BR /&gt;made mistakes&lt;BR /&gt;</description>
    <pubDate>Wed, 13 Dec 2017 00:50:10 GMT</pubDate>
    <dc:creator>junep</dc:creator>
    <dc:date>2017-12-13T00:50:10Z</dc:date>
    <item>
      <title>identify various observations for same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420619#M280665</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;&lt;P&gt;I am wondering how I might be able to identify different observations under the same variable by creating a dummy variable&lt;/P&gt;&lt;P&gt;I want to create a dummy variable called initial_product to identify which was the first product customers chose before they change to another product.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset I want to get looks like this ( I already have ID and product variables and observations), How do I create the variable initial_product ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; product&amp;nbsp; Initial_product&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Y&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any comments or suggestions.&lt;/P&gt;&lt;P&gt;I tried lag function, first.id/last.id but none of this gets me what I want. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 22:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420619#M280665</guid>
      <dc:creator>junep</dc:creator>
      <dc:date>2017-12-12T22:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: identify various observations for same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420624#M280666</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input ID product $ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 A Y&lt;BR /&gt;1 A Y&lt;BR /&gt;1 B N&lt;BR /&gt;2 B Y&lt;BR /&gt;2 C N&lt;BR /&gt;2 C N&lt;BR /&gt;3 A Y&lt;BR /&gt;3 B N&lt;BR /&gt;3 B N&lt;BR /&gt;;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;retain _t;&lt;BR /&gt;if first.id then&lt;BR /&gt;do;&lt;BR /&gt;_t=product;&lt;BR /&gt;initial_product='Y';&lt;BR /&gt;end;&lt;BR /&gt;else if product eq _t then initial_product='Y';&lt;BR /&gt;else initial_product='N';&lt;/P&gt;&lt;P&gt;drop _t;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 22:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420624#M280666</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-12T22:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: identify various observations for same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420628#M280667</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;junep wrote:
&lt;P&gt;I would appreciate any comments or suggestions.&lt;/P&gt;
&lt;P&gt;I tried lag function, first.id/last.id but none of this gets me what I want. Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Better for future questions be to show the approach you tried that got closest to what you wanted and explain why it did not meet your needs.&lt;/P&gt;
&lt;P&gt;Sometimes you may only be one option or order of operations from a correct solution. Since I can see several First. approaches that would generate what you want I suspect you may have been pretty close and just missed one bit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to explicitly&amp;nbsp;specify what happens if they switch back such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp; N&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp; ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also as you do more coding you might want to consider binary numeric coding with 1 for Y and 0 for N instead of character values.&lt;/P&gt;
&lt;P&gt;The Sum of a 1/0 coded variable over a group gives you the number of "yes" values. The mean would be the percent&amp;nbsp; "yes". And some procedures, regressions for instance, often require numeric results.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 22:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420628#M280667</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-12T22:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: identify various observations for same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420643#M280668</link>
      <description>Thanks. Your code produced results exactly the way I wanted. Greatly&lt;BR /&gt;appreciate your help.&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2017 00:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420643#M280668</guid>
      <dc:creator>junep</dc:creator>
      <dc:date>2017-12-13T00:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: identify various observations for same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420644#M280669</link>
      <description>Thanks for your advice. I wasn't getting anywhere with my codes so I knew&lt;BR /&gt;my codes were wrong. But as you mentioned it would be good to know where I&lt;BR /&gt;made mistakes&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2017 00:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-various-observations-for-same-variable/m-p/420644#M280669</guid>
      <dc:creator>junep</dc:creator>
      <dc:date>2017-12-13T00:50:10Z</dc:date>
    </item>
  </channel>
</rss>

