<?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: SAS Error 180-322 using a macro. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556205#M154930</link>
    <description>&lt;P&gt;Looks like a simple self join will let you calculate that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input x $ y :yymmdd. desired ;
  format y yymmdd10.;
cards;
a1154 2018-07-01 3
a1154 2018-06-22 2
a1154 2018-06-01 1
a1154 2018-05-25 0
a2266 2018-11-11 0
a2266 2017-01-01 0
a1997 2018-05-12 0
a2111 2016-05-18 1
a2111 2016-05-15 0
;
proc sql ;
create table want as
select a.*,count(b.y) as count
from have a
left join have b
on a.x=b.x 
and b.y between a.y-90 and a.y-1
group by a.x,a.y,a.desired
;
quit;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs      x               y    desired    count

 1     a1154    2018-05-25       0         0
 2     a1154    2018-06-01       1         1
 3     a1154    2018-06-22       2         2
 4     a1154    2018-07-01       3         3
 5     a1997    2018-05-12       0         0
 6     a2111    2016-05-15       0         0
 7     a2111    2016-05-18       1         1
 8     a2266    2017-01-01       0         0
 9     a2266    2018-11-11       0         0
&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 May 2019 17:35:36 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-04T17:35:36Z</dc:date>
    <item>
      <title>SAS Error 180-322 using a macro.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556028#M154823</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got 2 columns of data: x (a unique person identifier) and y (a date at which an action was performed by x). Some x'es occur more than once, and thus take up multiple rows. I've got the 2 columns sorted by x then by y so I have a list of all actions for each person's identifier and when they occurred. I would like to count the number of times that a person has performed an action in the past 90 days prior to date y, for all rows. My data (and my desired output) looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desired output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a1154&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7/1/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a1154&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6/22/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a1154&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6/1/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a1154&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/25/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a2266&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11/11/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a2266&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a1997&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/12/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a2111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/18/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a2111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/15/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do this, I am using lags. I am creating two variables (emp&amp;lt;n&amp;gt; and dd&amp;lt;n&amp;gt;) that use lag1, lag2, ... lag365 to compare each row with the nth row underneath it to see if there is an x match and if y is within the 90 day mark. I am doing this using macros. Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;macro check;&lt;/P&gt;&lt;P&gt;data macro_output;&lt;/P&gt;&lt;P&gt;set datasource;&lt;/P&gt;&lt;P&gt;do p=1 to 365;&lt;/P&gt;&lt;P&gt;emp&amp;amp;p = lag&amp;amp;p(x);&lt;/P&gt;&lt;P&gt;dd&amp;amp;p = lag&amp;amp;p(y)&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;mend check;&lt;/P&gt;&lt;P&gt;check;&lt;/P&gt;&lt;P&gt;macro still;&lt;/P&gt;&lt;P&gt;data finaloutput;&lt;/P&gt;&lt;P&gt;set macro_output;&lt;/P&gt;&lt;P&gt;output = 0;&lt;/P&gt;&lt;P&gt;n=1;&lt;/P&gt;&lt;P&gt;do until (n &amp;gt;= Last.x );&lt;/P&gt;&lt;P&gt;do p=1 to 365;&lt;/P&gt;&lt;P&gt;if x = emp&amp;amp;p &amp;amp; y &amp;lt; dd&amp;amp;p+90 then output = p;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;n=n+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;mend still;&lt;/P&gt;&lt;P&gt;still;&lt;/P&gt;&lt;P&gt;run;&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;When I run this, I get the error "ERROR 180-322: Statement is not valid or it is used out of proper order".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This error is occurring inside "run;", and SAS is telling me that the affected code is "%LET_CLIENTTASKLABEL=;" at line 59 and log line 51.&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;I have absolutely no idea what this means. From other threads and questions, I have seen this error usually attributed to a missing semicolon or a typo in the code. However, I do not believe this is the case here. I am writing this as a manually coded program inside Enterprise Guide 7.1. Would anyone please be able to help me figure this error out? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 17:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556028#M154823</guid>
      <dc:creator>jonesj22</dc:creator>
      <dc:date>2019-05-03T17:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Error 180-322 using a macro.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556031#M154825</link>
      <description>&lt;P&gt;place this command at the top of your program and run it again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then show us the ENTIRE SAS log, not just the error message. To do this, click on the {i} icon and paste the ENTIRE log into the window that appears.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 17:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556031#M154825</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-03T17:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Error 180-322 using a macro.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556036#M154828</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272384"&gt;@jonesj22&lt;/a&gt;&amp;nbsp; &amp;nbsp;I have absolutely no clue or understanding of the objective in having a macro here assuming my understanding of the logic i.e from what you wrote&lt;U&gt;&lt;EM&gt; "I would like to count the number of times that a person has performed an action in the past 90 days prior to date y, for all rows"&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;EM&gt;Assuming i understand this bit&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;/U&gt;The logic seems far too simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
     input x         $       y      :mmddyy10.   ;           
format y mmddyy10.;
 cards;
   a1154        7/1/2018                     3
   a1154        6/22/2018                   2
   a1154        6/1/2018                     1
   a1154        5/25/2018                   0
   a2266       11/11/2018                  0
   a2266       1/1/2017                     0
   a1997       5/12/2018                   0
   a2111       5/18/2016                   1
   a2111       5/15/2016                   0
   ;

 
proc sql;
create table want as
select a.*,sum( intnx('days',a.y,-90)&amp;lt;=b.y&amp;lt;a.y) as count 
from have a, have b
where a.x=b.x 
group by a.x,a.y
order by a.x, a.y desc;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I overlooked something, please correct me. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 18:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556036#M154828</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-03T18:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Error 180-322 using a macro.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556205#M154930</link>
      <description>&lt;P&gt;Looks like a simple self join will let you calculate that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input x $ y :yymmdd. desired ;
  format y yymmdd10.;
cards;
a1154 2018-07-01 3
a1154 2018-06-22 2
a1154 2018-06-01 1
a1154 2018-05-25 0
a2266 2018-11-11 0
a2266 2017-01-01 0
a1997 2018-05-12 0
a2111 2016-05-18 1
a2111 2016-05-15 0
;
proc sql ;
create table want as
select a.*,count(b.y) as count
from have a
left join have b
on a.x=b.x 
and b.y between a.y-90 and a.y-1
group by a.x,a.y,a.desired
;
quit;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs      x               y    desired    count

 1     a1154    2018-05-25       0         0
 2     a1154    2018-06-01       1         1
 3     a1154    2018-06-22       2         2
 4     a1154    2018-07-01       3         3
 5     a1997    2018-05-12       0         0
 6     a2111    2016-05-15       0         0
 7     a2111    2016-05-18       1         1
 8     a2266    2017-01-01       0         0
 9     a2266    2018-11-11       0         0
&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 May 2019 17:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556205#M154930</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-04T17:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Error 180-322 using a macro.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556424#M155007</link>
      <description>&lt;P&gt;This is exactly what I was looking to do, thank you. I am not nearly as proficient in SQL querying as I am in coding, and as such I did not even consider this approach to the problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 14:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Error-180-322-using-a-macro/m-p/556424#M155007</guid>
      <dc:creator>jonesj22</dc:creator>
      <dc:date>2019-05-06T14:11:31Z</dc:date>
    </item>
  </channel>
</rss>

