<?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 2 Syntax Errors in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316501#M69174</link>
    <description>&lt;P&gt;Hi, I am doing a momentum strategy research, and I am running into these errors when running a procedure (SAS Studio):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasError focus-line"&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, EXCEPT,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;~=.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;The procedure:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;proc sql;&lt;BR /&gt;create table umd&lt;BR /&gt;as select distinct a.permno, a.date, b.date as date1 label='sort_date', exp(sum(log(1+b.ret))) - 1 as cmret, b.ret&lt;BR /&gt;from commonstocks (keep=permno date) as a, commonstocks as b&lt;BR /&gt;where a.permno=b.permno and 0&amp;lt;=intck('month', b.date, a.date)&amp;lt;&amp;amp;J&lt;BR /&gt;group by a.permno, a.date&lt;BR /&gt;having count(b.ret)=&amp;amp;J;&lt;BR /&gt;quit;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/DIV&gt;</description>
    <pubDate>Sat, 03 Dec 2016 17:39:00 GMT</pubDate>
    <dc:creator>Raphaellima</dc:creator>
    <dc:date>2016-12-03T17:39:00Z</dc:date>
    <item>
      <title>2 Syntax Errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316501#M69174</link>
      <description>&lt;P&gt;Hi, I am doing a momentum strategy research, and I am running into these errors when running a procedure (SAS Studio):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasError focus-line"&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, EXCEPT,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;~=.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;The procedure:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;proc sql;&lt;BR /&gt;create table umd&lt;BR /&gt;as select distinct a.permno, a.date, b.date as date1 label='sort_date', exp(sum(log(1+b.ret))) - 1 as cmret, b.ret&lt;BR /&gt;from commonstocks (keep=permno date) as a, commonstocks as b&lt;BR /&gt;where a.permno=b.permno and 0&amp;lt;=intck('month', b.date, a.date)&amp;lt;&amp;amp;J&lt;BR /&gt;group by a.permno, a.date&lt;BR /&gt;having count(b.ret)=&amp;amp;J;&lt;BR /&gt;quit;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 03 Dec 2016 17:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316501#M69174</guid>
      <dc:creator>Raphaellima</dc:creator>
      <dc:date>2016-12-03T17:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Syntax Errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316508#M69179</link>
      <description>&lt;P&gt;You want rolling J-month cumulative returns for each permno.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks to me like you are usuing the CRSP monthly returns data, not the daily returns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that CRSP data is almost&amp;nbsp;always sorted by permno/date, you can use a DATA step to process the data much faster.&amp;nbsp; This program untested program makes the following assumptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;data sorted by permno/date&lt;/LI&gt;
&lt;LI&gt;the data are monthly&lt;/LI&gt;
&lt;LI&gt;RET is never missing&lt;/LI&gt;
&lt;LI&gt;The second example&amp;nbsp;works even when there are&amp;nbsp;"holes" (i.e.&amp;nbsp;missing months between the beginning and end of a permno).&lt;/LI&gt;
&lt;LI&gt;Your data has no more than 241 months for any given permno&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data umd (drop=month0_date m);
  set commonstocks;
  by permno;

  /* define  array to hold cumulative log(1+ret) starting month 0 up to 20 years*/
  array sumlog_retplus1 {0:240} _temporary_ ();

  if first.permno then do;
    month0_date=date;
    do m=0 to 240; sumlog_retplus1{m}=0; end;
  end;
  retain month0_date;

  m=intck('month',month0_date,date);
  if m=0 then sumlog_retplus1{m}=log(1+ret);
  else        sumlog_retplus1{m}=log(1+ret)+sumlog_retplus1{m-1};

  if m&amp;lt;&amp;amp;J then delete;
  else if m=&amp;amp;J then cmret=exp(sumlog_retplus1{m})-1;
  else              cmret=exp(sumlog_retplus1{m}-sumlog_retplus1{m-&amp;amp;J})-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second version accomodates holes in the monthly series:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data umd (drop=month0_date m m2 lastm);
  set commonstocks;
  by permno;

  /* define  array to hold cumulative log(1+ret) starting month 0 up to 20 years*/
  array sumlog_retplus1 {0:240} _temporary_ ();

  if first.permno then do;
    month0_date=date;
    do m=0 to 240; sumlog_retplus1{m}=0; end;
  end;
  retain month0_date;

  m=intck('month',month0_date,date);

  lastm=lag(m);

  if m=0 then sumlog_retplus1{m}=log(1+ret);
  else if m=lastm+1 then sumlog_retplus1{m}=log(1+ret)+sumlog_retplus1{m-1};
  else do m2=lastm+1 to m-1;
    else sumlog_retplus1{m2}=sumlog_retplus1{m2-1};
  end;

  if m&amp;lt;&amp;amp;J then delete;
  else if m=&amp;amp;J then cmret=exp(sumlog_retplus1{m})-1;
  else              cmret=exp(sumlog_retplus1{m}-sumlog_retplus1{m-&amp;amp;J})-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Dec 2016 12:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316508#M69179</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-04T12:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Syntax Errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316739#M69262</link>
      <description>&lt;P&gt;In the future please post the code and error message from the log and paste into a code box (either the {i} or run icon) to preserve formatting. The ERROR 22-322 is usually accompanied by an underscore under the postion in code that triggered the error message. Posting into a code box will maintain the orginal formatting and allow us to see where the underscore is in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the values of macro variable resolution help, so run the code with Options Mprint; so the log will show the code generated by the macro variable(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will say it looks a tad odd to me comparing the same value, &amp;amp;J, to both a number of months and another count (which might need CALCULATED to resolve in the HAVE clause) .&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 15:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Syntax-Errors/m-p/316739#M69262</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-05T15:44:50Z</dc:date>
    </item>
  </channel>
</rss>

