<?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: Find a difference between two variables conditional on other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334820#M75647</link>
    <description>Thank you so much. It works great.&lt;BR /&gt;For my case with multiple firms, I added firm identification variable in front of strike_price variable.&lt;BR /&gt;proc sort data=option;&lt;BR /&gt;by company strike_price expiry_date year;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set option;&lt;BR /&gt;by company strike_price expiry_date;&lt;BR /&gt;Change = dif(number);&lt;BR /&gt;&lt;BR /&gt;if first.expiry_date then&lt;BR /&gt;change=0;&lt;BR /&gt;run;</description>
    <pubDate>Wed, 22 Feb 2017 01:02:45 GMT</pubDate>
    <dc:creator>Sangho</dc:creator>
    <dc:date>2017-02-22T01:02:45Z</dc:date>
    <item>
      <title>Find a difference between two variables conditional on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334810#M75643</link>
      <description>&lt;P&gt;There is a stock option data with year, number of shares, strike price and expiry date.&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7384iF73196C67F0AAD6C/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture1.PNG" title="Capture1.PNG" /&gt;&lt;/P&gt;&lt;P&gt;with a code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data option;
input year number strike_price expiry_date;
datalines;
2010 100 8 20120101
2010 200 9 20130101
2010 250 6 20110101
2009 150 8 20120101
2009 250 9 20140101
2008 250 8 20120101
2008 450 9 20140101
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to find out whether there is a yearly change in number of shares only for options with the same strike price and expiry date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, observation 1 and 4, they have the same strike price and expiry date, so I record -50 for 2010. But observation 2 and 5, they have the same strike price but different expiry date, so I don't record anything. Eventually, I want something like below.&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7385iCA13208D7DD5FA0A/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture2.PNG" title="Capture2.PNG" /&gt;&lt;/P&gt;&lt;P&gt;This was just an example of one firm with 3 years, but in the dataset I have, there are multiple firms with multiple years.&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 23:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334810#M75643</guid>
      <dc:creator>Sangho</dc:creator>
      <dc:date>2017-02-21T23:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Find a difference between two variables conditional on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334811#M75644</link>
      <description>Basically, for two adjacent years, find a pair with same strike price and expiry date and record the difference</description>
      <pubDate>Tue, 21 Feb 2017 23:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334811#M75644</guid>
      <dc:creator>Sangho</dc:creator>
      <dc:date>2017-02-21T23:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find a difference between two variables conditional on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334813#M75645</link>
      <description>&lt;P&gt;It's probably best to expand your sample data so that we can account for the multiple firms/years from the start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is probably one case, where it's worth transposing your data to a wide format and then summarizing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or using DIF() function. This could be expanded by adding the Company to the BY group in the sort and data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data option;
	input year number strike_price expiry_date;
	datalines;
2010 100 8 20120101
2010 200 9 20130101
2010 250 6 20110101
2009 150 8 20120101
2009 250 9 20140101
2008 250 8 20120101
2008 450 9 20140101
;
run;

proc sort data=option;
	by strike_price expiry_date year;
run;

data want;
	set option;
	by strike_price expiry_date;
	Change = dif(number);

	if first.expiry_date then
		change=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2017 23:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334813#M75645</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-21T23:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Find a difference between two variables conditional on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334820#M75647</link>
      <description>Thank you so much. It works great.&lt;BR /&gt;For my case with multiple firms, I added firm identification variable in front of strike_price variable.&lt;BR /&gt;proc sort data=option;&lt;BR /&gt;by company strike_price expiry_date year;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set option;&lt;BR /&gt;by company strike_price expiry_date;&lt;BR /&gt;Change = dif(number);&lt;BR /&gt;&lt;BR /&gt;if first.expiry_date then&lt;BR /&gt;change=0;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 22 Feb 2017 01:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-difference-between-two-variables-conditional-on-other/m-p/334820#M75647</guid>
      <dc:creator>Sangho</dc:creator>
      <dc:date>2017-02-22T01:02:45Z</dc:date>
    </item>
  </channel>
</rss>

