<?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: someone pls explain the code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643991#M192285</link>
    <description>thanks</description>
    <pubDate>Wed, 29 Apr 2020 15:05:18 GMT</pubDate>
    <dc:creator>shweta_234</dc:creator>
    <dc:date>2020-04-29T15:05:18Z</dc:date>
    <item>
      <title>someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643976#M192275</link>
      <description>&lt;P&gt;data sue1/view=sue1;&lt;BR /&gt;set comp2;&lt;BR /&gt;by gvkey fqtr fyearq;&lt;BR /&gt;&lt;BR /&gt;if dif(fyearq)=1 then do;&lt;BR /&gt;lagadj=lag(ajexq); lageps_p=lag(epspxq);lageps_d=lag(epsfxq);&lt;BR /&gt;lagshr_p=lag(cshprq);lagshr_d=lag(cshfdq);lagspiq=lag(spiq);&lt;BR /&gt;end;&lt;BR /&gt;if first.gvkey then do;&lt;BR /&gt;lageps_d=.;lagadj=.; lageps_p=.;&lt;BR /&gt;lagshr_p=.;lagshr_d=.;lagspiq=.;end;&lt;BR /&gt;if basis='P' then do;&lt;BR /&gt;actual1=epspxq/ajexq; expected1=lageps_p/lagadj;&lt;BR /&gt;end;&lt;BR /&gt;else if basis='D' then do;&lt;BR /&gt;actual1=epsfxq/ajexq; expected1=lageps_d/lagadj;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;actual1=epspxq/ajexq; expected1=lageps_p/lagadj;&lt;BR /&gt;end;&lt;BR /&gt;sue1=(actual1-expected1)/(prccq/ajexq);&lt;BR /&gt;format sue1 percent7.4 rdq date9.;&lt;BR /&gt;label datadate='Calendar date of fiscal period end';&lt;BR /&gt;keep ticker permno gvkey conm fyearq fqtr fyr datadate&lt;BR /&gt;rdq sue1 basis&lt;BR /&gt;act prccq mcap;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 14:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643976#M192275</guid>
      <dc:creator>shweta_234</dc:creator>
      <dc:date>2020-04-29T14:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643977#M192276</link>
      <description>&lt;P&gt;Be specific. State the exact part of the code you don't understand. No one will try to explain all 27 lines of code that you posted.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 14:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643977#M192276</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-29T14:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643980#M192278</link>
      <description>&lt;P&gt;I have starred the codes that are not clear to me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sue1/view=sue1;&amp;nbsp; ***&lt;BR /&gt;set comp2;&lt;BR /&gt;by gvkey fqtr fyearq; ***&lt;BR /&gt;&lt;BR /&gt;if dif(fyearq)=1 then do; ***&amp;nbsp;&lt;BR /&gt;lagadj=lag(ajexq); lageps_p=lag(epspxq);lageps_d=lag(epsfxq);&lt;BR /&gt;lagshr_p=lag(cshprq);lagshr_d=lag(cshfdq);lagspiq=lag(spiq);&lt;BR /&gt;end;&lt;BR /&gt;if first.gvkey then do; ***&lt;BR /&gt;lageps_d=.;lagadj=.; lageps_p=.;&lt;BR /&gt;lagshr_p=.;lagshr_d=.;lagspiq=.;end;&lt;BR /&gt;if basis='P' then do;&lt;BR /&gt;actual1=epspxq/ajexq; expected1=lageps_p/lagadj;&lt;BR /&gt;end;&lt;BR /&gt;else if basis='D' then do;&lt;BR /&gt;actual1=epsfxq/ajexq; expected1=lageps_d/lagadj;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;actual1=epspxq/ajexq; expected1=lageps_p/lagadj;&lt;BR /&gt;end;&lt;BR /&gt;sue1=(actual1-expected1)/(prccq/ajexq);&lt;BR /&gt;format sue1 percent7.4 rdq date9.; ***&lt;BR /&gt;label datadate='Calendar date of fiscal period end';&lt;BR /&gt;keep ticker permno gvkey conm fyearq fqtr fyr datadate&lt;BR /&gt;rdq sue1 basis&lt;BR /&gt;act prccq mcap;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 14:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643980#M192278</guid>
      <dc:creator>shweta_234</dc:creator>
      <dc:date>2020-04-29T14:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643986#M192281</link>
      <description>&lt;P&gt;If you don't understand a Data step start or a By statement then it is time to take the Programming 1 class. Do a google search for "sas programming 1". It will guide you to the free online course for the entry into SAS programming. And &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Free-SAS-Learning-Resources/ta-p/425554" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Free-SAS-Learning-Resources/ta-p/425554&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And very likely, where ever you got the code from, it may not have performed as desired with the LAG function calls inside of an If /then/ do block of code.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 14:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643986#M192281</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-29T14:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643990#M192284</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1kh25to5o0wmvn1o4n4hsl3yyww.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;DATA Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p0yeyftk8ftuckn1o5qzy53284gz.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;BY Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1j60arf27ll4nn1ejavv3nby4pa.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;IF-THEN/ELSE Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n0el0y2a02ab1ln1pks3gbac1en3.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;DO Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n0d5oq7e0oia0wn13nsins0x8nmh.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FORMAT Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 15:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643990#M192284</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-29T15:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643991#M192285</link>
      <description>thanks</description>
      <pubDate>Wed, 29 Apr 2020 15:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643991#M192285</guid>
      <dc:creator>shweta_234</dc:creator>
      <dc:date>2020-04-29T15:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643993#M192286</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;data sue1/view=sue1;&amp;nbsp; ***&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;This creates a view instead of a SAS data set. For beginners, just leave out the &lt;FONT face="courier new,courier"&gt;/view=sue1&lt;/FONT&gt;, and create a data set with &lt;FONT face="courier new,courier"&gt;data sue1;&lt;/FONT&gt;&amp;nbsp;&lt;FONT face="arial,helvetica,sans-serif"&gt;and don't worry about views.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;by gvkey fqtr fyearq; ***&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;This indicates to SAS that the data is sorted by these three variables, which will be useful later.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;if dif(fyearq)=1 then do; ***&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The DIF function finds the difference between the value of fyearq in consecutive observations. If that difference = 1, then some action is taken. Please familiarize yourself with the SAS documentation, so you can look up functions that you find in existing SAS code, and also search for functions that might be useful in programs you write. &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=allprodslang&amp;amp;docsetTarget=syntaxByType-function.htm&amp;amp;locale=en" target="_self"&gt;Here&lt;/A&gt; is a list of all functions in alphabetical order.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;if first.gvkey then do; ***&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Because you told SAS the data is sorted, this finds the first record in a block of records where gvtkey is unchanged, and then takes some action.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;format sue1 percent7.4 rdq date9.; ***&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Formats change the appearance of variables. Sue1 will appear as a percent, in other words the value is between 0 and 1 but it will appear as a value between 0 and 100 with a percent sign at the end and four decimal place. Rdq will appear as a date.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 15:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643993#M192286</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-29T15:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: someone pls explain the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643994#M192287</link>
      <description>&lt;P&gt;One more item to add to your study list.&amp;nbsp; This code will generate the wrong result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if dif(fyearq)=1 then do;
lagadj=lag(ajexq); lageps_p=lag(epspxq);lageps_d=lag(epsfxq);
lagshr_p=lag(cshprq);lagshr_d=lag(cshfdq);lagspiq=lag(spiq);
end;
if first.gvkey then do;
lageps_d=.;lagadj=.; lageps_p=.;
lagshr_p=.;lagshr_d=.;lagspiq=.;end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The LAG function should (almost always) execute on every observation if you want accurate results.&amp;nbsp; This would be an improvement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
lagadj=lag(ajexq); lageps_p=lag(epspxq);lageps_d=lag(epsfxq);
lagshr_p=lag(cshprq);lagshr_d=lag(cshfdq);lagspiq=lag(spiq);

if first.gvkey  or dif(fyear1) ne 1 then do;
lageps_d=.;lagadj=.; lageps_p=.;
lagshr_p=.;lagshr_d=.;lagspiq=.;end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 15:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/someone-pls-explain-the-code/m-p/643994#M192287</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-04-29T15:16:58Z</dc:date>
    </item>
  </channel>
</rss>

