<?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: Compute Industry Adjusted Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251879#M268777</link>
    <description>&lt;P&gt;Post your code. You should be able to merge the results back in and then do your substraction in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend perhaps a SQL join and then you could even do the subtraction in one step. If you want, you can even calculate them all in one step.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2016 21:28:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-02-23T21:28:24Z</dc:date>
    <item>
      <title>Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251866#M268776</link>
      <description>&lt;P&gt;Hello! I have a coding question for SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying adjust my quarterly&amp;nbsp;ROA variable for each firm by industry means for each quarter. Thus, my end goal is to have IAROA= ROA - Industry Average for each quarter&amp;nbsp;for each firm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a visual, I have a primary dataset that looks similar to&amp;nbsp;this :&lt;/P&gt;&lt;P&gt;Firm &amp;nbsp; Year.Quarter &amp;nbsp;Industry &amp;nbsp; &amp;nbsp;ROA&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0125&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0359&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0451&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0215&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.125&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;2&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.135&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;2&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.097&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.102&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.029&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.024&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.035&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.028&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... and so forth through 2014 and 75 industry types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I have found the industry ROA means for each quarter&amp;nbsp;(2003-2014). using PROC MEANS. &amp;nbsp;Specifically I use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data=data.master&amp;nbsp;mean noprint;&lt;BR /&gt;output out=IROA&amp;nbsp;mean=;&lt;BR /&gt;by industry;&lt;BR /&gt;class yearquarter;&lt;BR /&gt;var roa ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for example, I have:&lt;/P&gt;&lt;P&gt;Industry &amp;nbsp;year.quarter &amp;nbsp; &amp;nbsp; &amp;nbsp; Industry ROA (IROA)&lt;/P&gt;&lt;P&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0171 &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0172 &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0173&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2003.4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0174 &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004.4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .112 &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .113 &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2003.4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .114 &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2004.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2004.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2004.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2004.4 &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... and so forth over all industries through 2014.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My end goal is to have:&lt;/P&gt;&lt;P&gt;Firm &amp;nbsp; Year.Quarter &amp;nbsp;Industry &amp;nbsp; &amp;nbsp;ROA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IROA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Industry Adjusted ROA&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0125 &amp;nbsp; &amp;nbsp; &amp;nbsp;.0171 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -.0046 &amp;nbsp; &amp;nbsp; (=&amp;nbsp;.0125-.0171)&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0359 &amp;nbsp; &amp;nbsp; &amp;nbsp;.0172&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.0187 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;(= .0359-.0172)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0451 &amp;nbsp; &amp;nbsp; &amp;nbsp;.0173 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0278&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0215 &amp;nbsp; &amp;nbsp;&amp;nbsp; .0174 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0041&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.125 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .014&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;2&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.135 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.112 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .023&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;2&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.097 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.113 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -.016&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.114 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -.012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.029&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0171 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0119&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.024 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.0172 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0068&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.035 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.0173 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0177&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.028 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.0174 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0106&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, all firms will have the IROA value depending on what industry they belong to and the year.quarter of the observation. &amp;nbsp;For example, Firms 1 and 3 belong to the same industry, so IROA takes on the same value for the same quarters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I have thousand of firms, 75ish industries, and my data spans 11 years, it is not feasible for me to code this manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A) Is there a macro that works well?&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;B) I can find the quarterly industry means, but I have not been able to merge it back into the primary dataset so every firm with the matching industry and quarter display the correct value for the industry roa variable. Only the first firm receives the industry variable value an the rest of the firms have "."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if there is any pertinent information missing that will allow you to help me with this code piece!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thank you in advance!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 20:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251866#M268776</guid>
      <dc:creator>klndsy</dc:creator>
      <dc:date>2016-02-23T20:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251879#M268777</link>
      <description>&lt;P&gt;Post your code. You should be able to merge the results back in and then do your substraction in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend perhaps a SQL join and then you could even do the subtraction in one step. If you want, you can even calculate them all in one step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 21:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251879#M268777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-23T21:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251884#M268778</link>
      <description>&lt;P&gt;Hi Reeza; thank you for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, I have been trying this with annual ROA (ideally I would like quarterly), so my code reflects that. I figured once I get it figured out with annual, then I can apply it to my quarterly data. &amp;nbsp;Additionally, sic2 is the industry variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=compustatrevised3; by sic2 year; run;&lt;BR /&gt;proc means data=compustatrevised3 mean noprint;&lt;BR /&gt;output out=IROA mean=;&lt;BR /&gt;by sic2;&lt;BR /&gt;class year;&lt;BR /&gt;var roa roa2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data IROA2;&lt;BR /&gt;set IROA (drop=_freq_);&lt;BR /&gt;if _type_=0 then delete;&lt;BR /&gt;rename roa=indroa roa2=indroa2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=compustatrevised3; by sic2 year;&amp;nbsp;&lt;BR /&gt;proc sort data=IROA2; by sic2 year; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data trialmerge;&lt;BR /&gt;merge compustatrevised3 IROA2;&lt;BR /&gt;by sic2 year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried multiple variations of the merge command, but this is the one that gets me closest. &amp;nbsp;However, it only fills the industry roa mean variable (indroa) for the first few firms of each year. &amp;nbsp;Even then, I can't exactly figure out the problem because most of the time&amp;nbsp;it will only fill the first firm, but sometimes it will fill 2, 3 or 4 firms with the industry roa value! &amp;nbsp;I attached a screenshot (word doc) of my merged output problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 22:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251884#M268778</guid>
      <dc:creator>klndsy</dc:creator>
      <dc:date>2016-02-23T22:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251885#M268779</link>
      <description>&lt;P&gt;Is your primary data sample reflective of your actual data format/structure?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 22:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251885#M268779</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-23T22:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251914#M268780</link>
      <description>&lt;P&gt;Yes, but it is currently sorted differently and includes a lot more variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tens of thousands of&amp;nbsp;firms spanning many different industries over a period of 2003-2014 with quarterly data. Each firm has a unique ROA each quarter (with some firms missing observations based on data availability).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My actual data set is sorted by industry(sic2) then year.quarter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a visual, my actual&amp;nbsp;dataset looks similarly sorted to&amp;nbsp;this (plus &amp;nbsp;many other variables) :&lt;/P&gt;&lt;P&gt;Firm &amp;nbsp; Year.Quarter &amp;nbsp;Industry &amp;nbsp; &amp;nbsp;ROA&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0125&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.029&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0359&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.024&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0451&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.035&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0215&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.028&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.1&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.125&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.2&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.135&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.3&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.097&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003.4&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.102&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251914#M268780</guid>
      <dc:creator>klndsy</dc:creator>
      <dc:date>2016-02-23T23:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251918#M268781</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74653"&gt;@klndsy﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, your code should work in principle (it could be simplified here and there, though) &lt;STRONG&gt;if&lt;/STRONG&gt; the data are what they should be. The output dataset in your attached screenshot, however, does not look like the result of a merge by SIC2 YEAR, but rather like the result of a merge by SIC2 &lt;STRONG&gt;YQ&lt;/STRONG&gt;&amp;nbsp;(see obs. no. 1553 in particular!).&amp;nbsp;One possible explanation is that some variable values shown in the screenshot are in fact &lt;U&gt;formatted&lt;/U&gt; values. If, for example, variable YEAR contains (varying!) SAS date values (like those in YQ) which are only formatted with format YEAR., a merge by SIC2 YEAR could indeed yield&amp;nbsp;results very similar to those shown in the screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comparing YQ with QUARTER&amp;nbsp;we see sort of an inconsistency which could impact your quarterly results as well: Variable YQ contains SAS date values, but sometimes they are varying within one quarter: YQ=15764='28FEB2003'd in obs. no. 1553 and YQ&lt;SPAN&gt;=15795='31MAR2003'd in obs. no. 1554 belong to the same quarter, but&amp;nbsp;only a variable with a &lt;EM&gt;constant&lt;/EM&gt; value (such as '2003.1') throughout a quarter would be suitable for merging by quarter. Again, it is not clear if variable QUARTER contains values such as 2003.1 (numeric or character?) or if it contains SAS date values, formatted with format YYQP..&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I think, once this issue is clarified, you are very close to getting the intended results.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just to suggest an alternative approach: You could let PROC STDIZE&amp;nbsp;compute both the IROA values&amp;nbsp;and the differences ROA - IROA. Please find below some sample code. However, you are so close to the finish line with your more elementary approach that you may want to&amp;nbsp;continue on this route.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
input firm yearquarter industry $ ROA;
cards;
1 2003.1 01 0.0125
1 2003.2 01 0.0359
1 2003.3 01 0.0451
1 2003.4 01 0.0215
2 2003.1 02 0.125
2 2003.2 02 0.135
2 2003.3 02 0.097
2 2003.4 02 0.102
3 2003.1 01 0.029
3 2003.2 01 0.024
3 2003.3 01 0.035
3 2003.4 01 0.028 
;

/* Sort input data and perform computations */

proc sort data=have;
by industry yearquarter;
run;

proc stdize data=have method=mean oprefix sprefix=IndAdj
            out=have_adj outstat=stats(where=(_type_='LOCATION') rename=(ROA=IROA));
var ROA;
by industry yearquarter;
run;

/* Merge firm-quarter level with industry-quarter level data and restore original sort order */

data want;
merge have_adj
      stats(drop=_type_);
by industry yearquarter;
label IndAdjROA='Industry Adjusted ROA';
run;

proc sort data=want;
by firm yearquarter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;I'll be back tomorrow (CET).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251918#M268781</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-23T23:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251931#M268783</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi FreelandReinhard! Thank you for your time!&amp;nbsp; Yes, my variables Year and YQ are both formatted variables from datadate which has the format 01012003. I thought I took care of this using put and input, but clearly I did not!&amp;nbsp; I have exhausted everything I can think of with this issue. Do you have any suggestions???&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 01:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/251931#M268783</guid>
      <dc:creator>klndsy</dc:creator>
      <dc:date>2016-02-24T01:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252001#M268784</link>
      <description>&lt;P&gt;You can do all calculations with one Proc SQL: Industry average ROA are calculated in subquery:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; want &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; P.Firm, &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;P.YearQuarter,&lt;/P&gt;
&lt;P&gt;P.Industry,&lt;/P&gt;
&lt;P&gt;P.ROA,&lt;/P&gt;
&lt;P&gt;I.IROA,&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; (P.roa-I.IROA) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; IAROA&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; primary P &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;left&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;join&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; Sub.Industry, Sub.YearQuarter, mean(Sub.ROA) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; IROA &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; Primary Sub &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;group&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; Sub.Industry, Sub.YearQuarter) I&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;on&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; P.Industry = I.Industry&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; P.YearQuarter = I.YearQuarter&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;order p.Firm, P.YearQuarter;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 10:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252001#M268784</guid>
      <dc:creator>AskoLötjönen</dc:creator>
      <dc:date>2016-02-24T10:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252002#M268785</link>
      <description>&lt;P&gt;I think, the easiest and safest way to prepare the aggregations and merges by year and by quarter is to create variables which contain year and quarter (incl. year), respectively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample data */
data old;
date='24FEB2016'd; /* numeric variable with values like 20508, possibly derived */
run;               /* from a raw date value like rawdate='24022016' by using    */
                   /* the INPUT function: date=input(rawdate, ddmmyy8.)         */

/* To be created */
data new;
set old;
year=year(date); /* numeric variable with values like 2016 */
quarter=put(date, yyqp.); /* character variable with values like '2016.1' */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say that YQ is formatted. My impression was rather that YQ is unformatted (screenshot shows SAS date values), but QUARTER could be formatted.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 10:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252002#M268785</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-24T10:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252008#M268786</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36190"&gt;@AskoLötjönen﻿&lt;/a&gt;: Sure, this would be the most straightforward approach. It just seemed that the OP is more familiar with the data step and PROC MEANS.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 10:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252008#M268786</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-24T10:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Industry Adjusted Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252066#M268787</link>
      <description>&lt;P&gt;Y'all were so wonderful and helpful. It is all working beautifully now. Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 15:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Industry-Adjusted-Variables/m-p/252066#M268787</guid>
      <dc:creator>klndsy</dc:creator>
      <dc:date>2016-02-24T15:11:22Z</dc:date>
    </item>
  </channel>
</rss>

