<?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: Create a variable a new variable based on two other variables when groups are small in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861164#M82532</link>
    <description>What determines an "item"? ID/Year are Unique and Store repeats twice each, I'm not sure your sample data adequately illustrates your problem. Can you add some more details about what you're trying to accomplish? &lt;BR /&gt;&lt;BR /&gt;You can get the output shown by using FIRST/LAST but I don't think it will work with your actual data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by store year;&lt;BR /&gt;if first.store then old_new = 'OLD';&lt;BR /&gt;if last.Store then old_new = 'NEW';&lt;BR /&gt;run;&lt;BR /&gt;</description>
    <pubDate>Mon, 27 Feb 2023 17:42:18 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-02-27T17:42:18Z</dc:date>
    <item>
      <title>Create a variable a new variable based on two other variables when groups are small</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861159#M82531</link>
      <description>&lt;P&gt;We have this dataset. There are only two items from the same store. And we want to determine items as new/old within the same store based on the year.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;YEAR&lt;/TD&gt;&lt;TD&gt;STORE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD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103&lt;/TD&gt;&lt;TD&gt;2004&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;NEW&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;104&lt;/TD&gt;&lt;TD&gt;2005&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;OLD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;105&lt;/TD&gt;&lt;TD&gt;2007&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;NEW&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 27 Feb 2023 17:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861159#M82531</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-02-27T17:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create a variable a new variable based on two other variables when groups are small</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861164#M82532</link>
      <description>What determines an "item"? ID/Year are Unique and Store repeats twice each, I'm not sure your sample data adequately illustrates your problem. Can you add some more details about what you're trying to accomplish? &lt;BR /&gt;&lt;BR /&gt;You can get the output shown by using FIRST/LAST but I don't think it will work with your actual data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by store year;&lt;BR /&gt;if first.store then old_new = 'OLD';&lt;BR /&gt;if last.Store then old_new = 'NEW';&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Feb 2023 17:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861164#M82532</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-27T17:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create a variable a new variable based on two other variables when groups are small</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861167#M82533</link>
      <description>Yes, ID is each item and year is year of manufacturing. We want to determine within the same store, which item is older based on when manufacturing date (year).</description>
      <pubDate>Mon, 27 Feb 2023 17:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/861167#M82533</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-02-27T17:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a variable a new variable based on two other variables when groups are small</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/871215#M82649</link>
      <description>&lt;P&gt;To get the desired result use the proc sort procedure, then use first.store to get the new_items else old_items.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please refer to code-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data=dt; by id year store; run;
proc sort data=dt; by store; run;

data dt1;
set dt;
by store;
if first.store then old_new = "New";
else old_new= "old";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;-Vijay&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-variable-a-new-variable-based-on-two-other-variables/m-p/871215#M82649</guid>
      <dc:creator>vijaypratap0195</dc:creator>
      <dc:date>2023-04-21T17:52:41Z</dc:date>
    </item>
  </channel>
</rss>

