<?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: Automat  sum case statements with macro or with array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614648#M179741</link>
    <description>&lt;P&gt;I think there is no point to show log when the code is totally wrong.&lt;/P&gt;
&lt;P&gt;But as you asked i will how it&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"15AUG2019"d then Y else 0 end ) as Accum_Y_Til"15AUG2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 2; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"20AUG2019"d then Y else 0 end ) as Accum_Y_Til"20AUG2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 3; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;2 The SAS System 09:04 Wednesday, January 1, 2020&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"25AUG2019"d then Y else 0 end ) as Accum_Y_Til"25AUG2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 4; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"02SEP2019"d then Y else 0 end ) as Accum_Y_Til"02SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 5; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"05SEP2019"d then Y else 0 end ) as Accum_Y_Til"05SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 6; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"10SEP2019"d then Y else 0 end ) as Accum_Y_Til"10SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 7; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"15SEP2019"d then Y else 0 end ) as Accum_Y_Til"15SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 8; loop will not iterate again.&lt;BR /&gt;MLOGIC(MMACRO): Ending execution.&lt;BR /&gt;35 &lt;BR /&gt;36 &lt;BR /&gt;37 PROC SQL;&lt;BR /&gt;38 create table Wanted as&lt;BR /&gt;39 select ID,%mmacro&lt;BR /&gt;MLOGIC(MMACRO): Beginning execution.&lt;BR /&gt;MLOGIC(MMACRO): %DO loop beginning; index variable J; start value is 1; stop value is 7; by value is 1. &lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;3 The SAS System 09:04 Wednesday, January 1, 2020&lt;/P&gt;
&lt;P&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"15AUG2019"d then Y else 0 end ) as Accum_Y_Til"15AUG2019"d,;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "DDATE".&lt;BR /&gt;39 Accum_Y_Til"15AUG2019"d&lt;BR /&gt;____________&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;MLOGIC(MMACRO): %DO loop index variable J is now 2; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;39 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"20AUG2019"d then Y else 0 end ) as Accum_Y_Til"20AUG2019"d,;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT, FROM, INFORMAT, INTO, LABEL, LEN, &lt;BR /&gt;LENGTH, TRANSCODE.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jan 2020 08:30:31 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-01-01T08:30:31Z</dc:date>
    <item>
      <title>Automat  sum case statements with macro or with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614643#M179738</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am trying to create automat code but there is an error.&lt;/P&gt;
&lt;P&gt;What is the correct way to do it please?&lt;/P&gt;
&lt;P&gt;Should I&amp;nbsp; use macro or array?&lt;/P&gt;
&lt;P&gt;What is the correct code to do it?&lt;/P&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;%let VarList=21776+21781+21786+21794+21797+21802+21807;
%let VarList2=190815+190820+190825+190902+190905+190910+190915;
%let count = %sysfunc(countw(&amp;amp;VarList));


Data RawTbl;
informat  DateAction date9.; 
format DateAction date9.; 
Input ID DateAction Y;
Cards;
1 '12AUG2019'd 10
1 '13AUG2019'd 20
1 '14AUG2019'd 30
1 '18AUG2019'd 40
1 '21AUG2019'd 50
1 '14SEP2019'd 60
2 '13AUG2019'd 70
2 '13AUG2019'd 80
2 '14AUG2019'd 90
2 '14AUG2019'd 100
2 '17AUG2019'd 110
2 '14SEP2019'd 120
;
Run;

/*Way to perform maunally*/
PROC SQL;
	create table Wanted  as
	select ID,
       sum(case when DateAction&amp;lt;'15AUG2019'd then Y else 0 end ) as AccumTil_l5AUG2019,
	   sum(case when DateAction&amp;lt;'20AUG2019'd then Y else 0 end ) as AccumTil_20AUG2019,
	   sum(case when DateAction&amp;lt;'25AUG2019'd then Y else 0 end ) as AccumTil_25AUG2019,
	   sum(case when DateAction&amp;lt;'02SEP2019'd then Y else 0 end ) as AccumTil_02SEP2019,
	   sum(case when DateAction&amp;lt;'05SEP2019'd then Y else 0 end ) as AccumTil_05SEP2019,
	   sum(case when DateAction&amp;lt;'10SEP2019'd then Y else 0 end ) as AccumTil_10SEP2019,
	   sum(case when DateAction&amp;lt;'15SEP2019'd then Y else 0 end ) as AccumTil_15SEP2019
	from  RawTbl
	group by ID
;
QUIT;

/*Task-Automize*/
%macro mmacro; 
%do j=1 %to &amp;amp;count.;
%let ddate=%scan(&amp;amp;VarList.,&amp;amp;j.,+);
sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;
%end;
%mend mmacro;
%mmacro; 


PROC SQL;
	create table Wanted  as
	select ID,%mmacro
	from  RawTbl
	group by ID
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jan 2020 07:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614643#M179738</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-01T07:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Automat  sum case statements with macro or with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614647#M179740</link>
      <description>&lt;P&gt;First thing I see if that you execute the macro directly after the definition unnecessarily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please include a log of the error.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 08:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614647#M179740</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-01T08:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Automat  sum case statements with macro or with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614648#M179741</link>
      <description>&lt;P&gt;I think there is no point to show log when the code is totally wrong.&lt;/P&gt;
&lt;P&gt;But as you asked i will how it&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"15AUG2019"d then Y else 0 end ) as Accum_Y_Til"15AUG2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 2; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"20AUG2019"d then Y else 0 end ) as Accum_Y_Til"20AUG2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 3; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;2 The SAS System 09:04 Wednesday, January 1, 2020&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"25AUG2019"d then Y else 0 end ) as Accum_Y_Til"25AUG2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 4; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"02SEP2019"d then Y else 0 end ) as Accum_Y_Til"02SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 5; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"05SEP2019"d then Y else 0 end ) as Accum_Y_Til"05SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 6; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"10SEP2019"d then Y else 0 end ) as Accum_Y_Til"10SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 7; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;34 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"15SEP2019"d then Y else 0 end ) as Accum_Y_Til"15SEP2019"d,;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;MLOGIC(MMACRO): %DO loop index variable J is now 8; loop will not iterate again.&lt;BR /&gt;MLOGIC(MMACRO): Ending execution.&lt;BR /&gt;35 &lt;BR /&gt;36 &lt;BR /&gt;37 PROC SQL;&lt;BR /&gt;38 create table Wanted as&lt;BR /&gt;39 select ID,%mmacro&lt;BR /&gt;MLOGIC(MMACRO): Beginning execution.&lt;BR /&gt;MLOGIC(MMACRO): %DO loop beginning; index variable J; start value is 1; stop value is 7; by value is 1. &lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;3 The SAS System 09:04 Wednesday, January 1, 2020&lt;/P&gt;
&lt;P&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"15AUG2019"d then Y else 0 end ) as Accum_Y_Til"15AUG2019"d,;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "DDATE".&lt;BR /&gt;39 Accum_Y_Til"15AUG2019"d&lt;BR /&gt;____________&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;MLOGIC(MMACRO): %DO loop index variable J is now 2; loop will iterate again.&lt;BR /&gt;MLOGIC(MMACRO): %LET (variable name is DDATE)&lt;BR /&gt;NOTE: Line generated by the invoked macro "MMACRO".&lt;BR /&gt;39 sum(case when DateAction&amp;lt;&amp;amp;ddate. then Y else 0 end ) as Accum_Y_Til&amp;amp;ddate.,;&lt;BR /&gt;___&lt;BR /&gt;180&lt;BR /&gt;MPRINT(MMACRO): sum(case when DateAction&amp;lt;"20AUG2019"d then Y else 0 end ) as Accum_Y_Til"20AUG2019"d,;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT, FROM, INFORMAT, INTO, LABEL, LEN, &lt;BR /&gt;LENGTH, TRANSCODE.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 08:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614648#M179741</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-01T08:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Automat  sum case statements with macro or with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614649#M179742</link>
      <description>&lt;P&gt;Remove the macro call that you make immediately after the definition. You also have a comma after ddate. (the second one).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;see what happens after removing that&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 09:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614649#M179742</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-01T09:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Automat  sum case statements with macro or with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614654#M179746</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy new year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an attempt to automatize the calculation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date_ref_table;
	input date_ref:date9.;
	name_var = cats("AccumTil_", put(date_ref,date9.));
	datalines;
'15AUG2019'd
'20AUG2019'd
'25AUG2019'd
'02SEP2019'd
'05SEP2019'd
'10SEP2019'd
'15SEP2019'd
;
run;

proc sql noprint;
	select date_ref into: date_ref separated by " " from date_ref_table;
	select name_var into: list_var separated by " " from date_ref_table;
	select count(name_var) into: count from date_ref_table;
quit;


data RawTbl2;
	set RawTbl;
	array date_ref (&amp;amp;count) _temporary_ (&amp;amp;date_ref);
	array AccumTil_(*) &amp;amp;list_var;
	format date_ref: date9.;

	do i=1 to 7;

		if DateAction &amp;lt; date_ref(i) then AccumTil_(i)=Y;
		else AccumTil_(i)=0;
	end;
	
	drop i Y DateAction;
run;

proc means data=RawTbl2 sum noprint;
	var AccumTil_:;
	class id;
	ways 1;
	output out=want (drop=_type_ _freq_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jan 2020 10:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614654#M179746</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-01T10:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Automat  sum case statements with macro or with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614659#M179751</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;perfect!&lt;/P&gt;
&lt;P&gt;thank you all&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 12:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automat-sum-case-statements-with-macro-or-with-array/m-p/614659#M179751</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-01T12:41:32Z</dc:date>
    </item>
  </channel>
</rss>

