<?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: perform a %DO loop over a list of values and use proc sql, data step, and another macro between in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/335426#M272199</link>
    <description>&lt;P&gt;Thanks a lot for the reply,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached my data source for you. in the code&amp;nbsp;"datasource20012017filtered" is actually same as this dataset.&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>Thu, 23 Feb 2017 22:01:52 GMT</pubDate>
    <dc:creator>samira</dc:creator>
    <dc:date>2017-02-23T22:01:52Z</dc:date>
    <item>
      <title>perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333859#M272177</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to peform a do loop over a string variable (disease name and region) and use proc sql, data step, and proc reg&amp;nbsp;within that loop. The following shows what I need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;DO LOOP OVER EACH DISEASE AND REGION;&lt;/STRONG&gt;

&amp;nbsp; &amp;nbsp;   proc sql;
&amp;nbsp; &amp;nbsp; &amp;nbsp; create table a &amp;nbsp;as select week, year, count from&amp;nbsp;table &lt;BR /&gt;      where region="&amp;amp;region" and disease="&amp;amp;disease"
&amp;nbsp; &amp;nbsp;   quit;

      data datastep;
&amp;nbsp;     /*do some stuff*/
      run;

      proc reg data=statprocess;
      model avg=x0;
      output out=trig p=yhat r=e stdp=sd;
      run;

&lt;STRONG&gt;END;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;I would be appriciate if someone help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for sharing your knowledge&lt;/P&gt;&lt;P&gt;Samira&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333859#M272177</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-17T17:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333860#M272178</link>
      <description>&lt;P&gt;Why not use BY groups instead?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333860#M272178</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-17T17:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333862#M272179</link>
      <description>do you mean group by in sql? if so how can I execute all thoses code for each value ?</description>
      <pubDate>Fri, 17 Feb 2017 17:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333862#M272179</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-17T17:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333864#M272180</link>
      <description>&lt;P&gt;Wrap your code in a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analysis(region,disease);

/* your code */

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then get a list of distinct value pairs from the source dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table control as
select distinct region, disease
from table;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use that to repeatedly execute the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set control;
call execute('%analysis('!!strip(region)!!','!!strip(disease)!!')');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333864#M272180</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-17T17:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333888#M272181</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      create table a  as select week, year, count from table ;
      quit;

      data datastep;
      /*do some stuff*/
/*Depends on what goes on here if you need code*/
      run;

      proc reg data=statprocess;
by region disease;
      model avg=x0;
      output out=trig p=yhat r=e stdp=sd;
      run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 18:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333888#M272181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-17T18:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333890#M272182</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may find this reference helpful.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 18:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333890#M272182</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-17T18:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333914#M272183</link>
      <description>&lt;P&gt;Thank you very much for your response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified my code based on your comment. Here is the code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analysis(dise, regi);

  proc sql;
      create table withState as
      select week, year, sum(count) from data.datasource20012017filtered
      where disease="&amp;amp;dise"
      group by week, year
      union 
      select * from data.mtx3;
   quit;
 
 proc sql;
      create table withoutState as
      select week, year, count from data.datasource20012017filtered
      where region="&amp;amp;regi" and disease="&amp;amp;dise"
      union 
      select * from data.mtx3;
   quit;

   data main_query;
   if "&amp;amp;regi"="STATE" then
   set withState;
   else set withoutState;
   run;
   
   proc sql;
   create table sumup_count as 
   select distinct week, year , sum(count) as count
   from main_query
   group by week, year;
   quit;
   
   proc sort data=sumup_count;
   by week year; 
   run;
   
  
 *using the following proc transpose, we are gonna make the matrix;
   proc transpose data=sumup_count out=want (DROP=_LABEL_ AND _NAME_) prefix=year ;
   by week;
   id year;
   var count;
   run;

   data the_matrix_query_withnull;
   retain week year2001 year2002 year2003 year2004 year2005 year2006 year2007 year2008 year2009 year2010 year2011 year2012 year2013 year2014 year2015 year2016 year2017;
   set want;
   run;
  
    *the additional below data step is because we handel 
  the null and zero issue in the recomputation limits part. 
  in fact we need to put zero instead of null on missing value;
   data the_matrix_query;
   set the_matrix_query_withnull;
   if year2001=" " then year2001=0;
   if year2002=" " then year2002=0;
   if year2003=" " then year2003=0;
   if year2004=" " then year2004=0;
   if year2005=" " then year2005=0;
   if year2006=" " then year2006=0;
   if year2007=" " then year2007=0;
   if year2008=" " then year2008=0;
   if year2009=" " then year2009=0;
   if year2010=" " then year2010=0;
   if year2011=" " then year2011=0;
   if year2012=" " then year2012=0;
   if year2013=" " then year2013=0;
   if year2014=" " then year2014=0;
   if year2015=" " then year2015=0;
   if year2016=" " then year2016=0;
   if year2017=" " then year2017=0;
   run;

data statprocess;
	set the_matrix_query;
    avg=(sum(of year2007-year2016))/10;
 	x0=1;
 	x1=sin(2*3.14159*week/52);
	x2=cos(2*3.14159*week/52); 
 	x3=sin(4*3.14159*week/52); 
 	x4=cos(4*3.14159*week/52);
run;
   
    
      proc reg data=statprocess;
         model avg=x0;
         output out=trig p=yhat r=e stdp=sd;
      run;

%mend analysis;
%analysis
 
 proc sql;
 create table control as
 select distinct region, disease from Report8;
 quit;
 
 data _null_;
 set control;
 call execute('%analysis('!!strip(region)!!','!!strip(disease)!!')');
 run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as you can see there is a lot to execute in macro analysis. I ran the code and I got the following error(20):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Re: Macro Error: More positional parameters found than defined.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;also the running time its about 5 min which is too much. is there any way to do make this runing time lower?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your help in advance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Samira&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 20:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333914#M272183</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-17T20:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333920#M272184</link>
      <description>&lt;P&gt;When writing a macro, first make sure the code inside works. As written it shouldn't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is incorrect:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
   data main_query;
   if "&amp;amp;regi"="STATE" then
   set withState;
   else set withoutState;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need conditional logic, then it's %if/%then/%else etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your macro call, via call execute, build the string first and then pass it to call execute. This will help you avoid errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use PROC STDIZE to set the missing to 0, rather than a data step, if its easier. It's dynamic so it's easier to modify if you have multiple years. Your IF/THEN in that step is also incorrect, because you're checking for missing with a blank - which means a character variable, but then you assign a numeric value instead of character value. Enclose the 0 in quotes. If you don't want PROC STDIZE, use an array instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are mistakes throughout so I go back to my first suggestion - make sure it's working without macro variables first, or hard coded macro variables. Then make it into a macro. Your base code&amp;nbsp;will not be correct as shown.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 20:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333920#M272184</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-17T20:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333924#M272185</link>
      <description>&lt;P&gt;Other common mistakes I see after another quick skim - all output tables will have the same name regardless of the run. This means you overwrite previous results if you run the macro more than once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, like I first mentioned, &lt;STRONG&gt;you don't need a macro for this at all.&lt;/STRONG&gt; It's likely making it harder to accomplish really. For academic reasons, learning, it may be worth fixing, but learning how to do it without macro's would be more useful in the long run. My 2 cents.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 20:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333924#M272185</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-17T20:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333972#M272186</link>
      <description>&lt;P&gt;You probably have a region or disease with a comma in it.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 21:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333972#M272186</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-17T21:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333975#M272187</link>
      <description>&lt;P&gt;So to convert your logic from needing to run separate steps for each group to just using BY processing you would convert your posted logic to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Get ALL the data ;
data all;
  set TABLE ;
  keep region disease week year count ;
run;

* Manipulate the data ;
data statprocess; 
   set all ;
      /*do some stuff*/
run;

* Make sure the data is order by the groups;
proc sort =statprocess ;
  by region disease ;
run;

* Run the analysis;
proc reg data=statprocess;
   by region disease ;
   model avg=x0;
   output out=trig p=yhat r=e stdp=sd;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 21:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333975#M272187</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-17T21:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333983#M272188</link>
      <description>Thanks KurtBremser for your nice answer. I just have another question. if in each iteration I want to store the result into a dataset (incrementally). how can I gather all the result in one dataset?</description>
      <pubDate>Fri, 17 Feb 2017 22:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333983#M272188</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-17T22:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333984#M272189</link>
      <description>thanks a lot for the time you spent. you are right. the error came from main_query</description>
      <pubDate>Fri, 17 Feb 2017 22:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/333984#M272189</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-17T22:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334045#M272190</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98482"&gt;@samira&lt;/a&gt; wrote:&lt;BR /&gt;Thanks KurtBremser for your nice answer. I just have another question. if in each iteration I want to store the result into a dataset (incrementally). how can I gather all the result in one dataset?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have this output statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;output out=trig /* further options */;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expand it with your macro parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;output out=trig_&amp;amp;region._&amp;amp;disease. /* further options */;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, to put everything into one dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set control end=done;
if _n_ = 1
then do;
  call execute('data all_results; set');
end;
call execute('trig_'!!strip(region)!!'_'!!strip(disease)!!' ');
if done
then do;
  call execute(';run;');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Feb 2017 10:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334045#M272190</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-18T10:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334714#M272191</link>
      <description>&lt;P&gt;Thanks a lot for the inforemation. I used this code to get the value of each iteration. I have tried to understand your code and utilize it in my code but I got some error which does not make sense to me. here is the first error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: CALL EXECUTE generated line.
1 + data all_results; set
NOTE: Line generated by the CALL EXECUTE routine.
2 + trig_CENTRAL_ADULT RESPIRATORY DISTRESS SYNDROME (ARDS)
____
22
&lt;STRONG&gt;ERROR 22-7: Invalid option name ARDS.&lt;/STRONG&gt;
&amp;nbsp;
3 + trig_CENTRAL_ANAPLASMA PHAGOCYTOPHILUM
4 + trig_CENTRAL_ANIMAL BITES
5 + trig_CENTRAL_BOTULISM INFANT
6 + trig_CENTRAL_BRUCELLOSIS
7 + trig_CENTRAL_CAMPYLOBACTERIOSIS
8 + trig_CENTRAL_CHIKUNGUNYA
9 + trig_CENTRAL_COCCIDIOIDOMYCOSIS
NOTE: Line generated by the CALL EXECUTE routine.
10 + trig_CENTRAL_CREUTZFELDT-JAKOB DISEASE (CJD)
___
22
&lt;STRONG&gt;ERROR: Missing numeric suffix on a numbered data set list (WORK.trig_CENTRAL_CREUTZFELDT-WORK.JAKOB).
ERROR 22-7: Invalid option name CJD.
&amp;nbsp;&lt;/STRONG&gt;
11 + trig_CENTRAL_CRYPTOSPORIDIOSIS
12 + trig_CENTRAL_CYCLOSPORIASIS
13 + trig_CENTRAL_DENGUE FEVER
14 + trig_CENTRAL_E. COLI O157 H7
&lt;STRONG&gt;ERROR: Libref 'trig_CENTRAL_E' exceeds 8 characters.&lt;/STRONG&gt;
15 + trig_CENTRAL_EHRLICHIA CHAFFEENSIS
16 + trig_CENTRAL_EHRLICHIA EWINGII
17 + trig_CENTRAL_EHRLICHIOSIS ANAPLASMOSIS UNDETERMINED
18 + trig_CENTRAL_GIARDIASIS
NOTE: Line generated by the CALL EXECUTE routine.
19 + trig_CENTRAL_HAEMOPHILUS INFLUENZAE, INVASIVE
_
22
200
&lt;STRONG&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY,
KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/STRONG&gt;
&amp;nbsp;
&lt;STRONG&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/STRONG&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the following is my code which is edited based on your comments:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analysis(dise, regi);
 
  proc sql;
      create table withState as
      select week, year, sum(count) from data.datasource20012017filtered
      where disease="&amp;amp;dise"
      group by week, year
      union 
      select * from data.mtx3;
   quit;
 
 proc sql;
      create table withoutState as
      select week, year, count from data.datasource20012017filtered
      where region="&amp;amp;regi" and disease="&amp;amp;dise"
      union 
      select * from data.mtx3;
   quit;

   proc sql;
   create table sumup_count as 
   select distinct week, year , sum(count) as count
   from withoutState 
   group by week, year;
   quit;
   
   proc sort data=sumup_count;
   by week year; 
   run;
   
  
 *using the following proc transpose, we are gonna make the matrix;
   proc transpose data=sumup_count out=want (DROP=_LABEL_ AND _NAME_) prefix=year ;
   by week;
   id year;
   var count;
   run;

   data the_matrix_query_withnull;
   retain week year2001 year2002 year2003 year2004 year2005 year2006 year2007 year2008 year2009 year2010 year2011 year2012 year2013 year2014 year2015 year2016 year2017;
   set want;
   run;
  
    *the additional below data step is because we handel 
  the null and zero issue in the recomputation limits part. 
  in fact we need to put zero instead of null on missing value;
  data the_matrix_query;
   set the_matrix_query_withnull;
   if year2001=" " then year2001=0;
   if year2002=" " then year2002=0;
   if year2003=" " then year2003=0;
   if year2004=" " then year2004=0;
   if year2005=" " then year2005=0;
   if year2006=" " then year2006=0;
   if year2007=" " then year2007=0;
   if year2008=" " then year2008=0;
   if year2009=" " then year2009=0;
   if year2010=" " then year2010=0;
   if year2011=" " then year2011=0;
   if year2012=" " then year2012=0;
   if year2013=" " then year2013=0;
   if year2014=" " then year2014=0;
   if year2015=" " then year2015=0;
   if year2016=" " then year2016=0;
   if year2017=" " then year2017=0;
   run;

data statprocess;
	set the_matrix_query;
    avg=(sum(of year2007-year2016))/10;
 	x0=1;
 	x1=sin(2*3.14159*week/52);
	x2=cos(2*3.14159*week/52); 
 	x3=sin(4*3.14159*week/52); 
 	x4=cos(4*3.14159*week/52);
run;
   


  /* %if ( &amp;amp;regressionModel = 0 ) %then
   %do;*/
     * Zero order model u = a0 + a1*t;
      
      proc reg data=statprocess;
         model avg=x0;
         output out=trig_&amp;amp;regi._&amp;amp;dise. p=yhat r=e stdp=sd;
         
         run;
         

%mend analysis;
%analysis
 
 proc sql;
 create table control as
 select distinct region, disease from Report8;
 quit;
 
data _null_;
set control end=done;
if _n_ = 1
then do;
  call execute('data all_results; set');
end;
call execute('trig_'!!strip(region)!!'_'!!strip(disease)!!' ');
if done
then do;
  call execute(';run;');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;appriciate all your helps in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Samira&lt;/P&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Feb 2017 17:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334714#M272191</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-21T17:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334715#M272192</link>
      <description>thank you for your answer.&lt;BR /&gt;&lt;BR /&gt;based on my code I need too make a matrix for each disease and region before doing regression analysis, that is why I cannot use group by in this case</description>
      <pubDate>Tue, 21 Feb 2017 17:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334715#M272192</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-21T17:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334716#M272193</link>
      <description>thank you for your answer.&lt;BR /&gt;&lt;BR /&gt;based on my code I need too make a matrix for each disease and region before doing regression analysis, that is why I cannot use group by in this case</description>
      <pubDate>Tue, 21 Feb 2017 17:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334716#M272193</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-21T17:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334742#M272194</link>
      <description>&lt;P&gt;You need to get rid of blanks in your region and disease variables. Replace them with underlines, using the translate() function.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 19:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334742#M272194</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-21T19:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334842#M272195</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98482"&gt;@samira&lt;/a&gt; wrote:&lt;BR /&gt;thank you for your answer.&lt;BR /&gt;&lt;BR /&gt;based on my code I need too make a matrix for each disease and region before doing regression analysis, that is why I cannot use group by in this case&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The results are the same, regardless of using BY group or a macro loop.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 05:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/334842#M272195</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-22T05:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: perform a %DO loop over a list of values and use proc sql, data step, and another macro between</title>
      <link>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/335381#M272196</link>
      <description>&lt;P&gt;Dear KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Over te last couple of days I was&amp;nbsp;struggling to fix my code and get result based on your comments. your solution is intresting to me and I am sure this is the best way to do loop over list of disease name and regions. However I have still problem&amp;nbsp;which I coudnt found out the reason over last 2 days. The problem is I couldnt get each loop's output and save into one data set. the below code gave me only one row. Please see my comments in the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the following is my code after editing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data compres;
set data.datasource20012017filtered;
disease=tranwrd(disease, ",", " ");
disease=tranwrd(disease, "&amp;lt;", " ");
disease=tranwrd(disease, "(", " ");
disease=tranwrd(disease, ")", " ");
disease=tranwrd(disease, ".", " ");
disease=tranwrd(disease, "-", " ");
disease=compress(disease);
disease=substr(disease,1,min(length(disease),16));
run;

proc sql;
 create table control as
 select distinct "EASTERN" as region, disease from Report8
 union select distinct "CENTRAL" as region, disease from Report8
  union select distinct "SOUTHWEST" as region, disease from Report8  
   union select distinct "SOUTHEAST" as region, disease from Report8  
    union select distinct "NORTHWEST" as region, disease from Report8;
 quit;
 
 data compres2;
 set control;
 disease=tranwrd(disease, ",", " ");
 disease=tranwrd(disease, "&amp;lt;", " ");
 disease=tranwrd(disease, "(", " ");
 disease=tranwrd(disease, ")", " ");
 disease=tranwrd(disease, ".", " ");
 disease=tranwrd(disease, "-", " ");
 disease=compress(disease);
 disease=substr(disease,1,min(length(disease),16));
 run;
 
%macro analysis(regi,dise,counter);
%put &amp;amp;regi;
%put &amp;amp;dise;
%put &amp;amp;counter;

 proc sql;
      create table withoutState as
      select week, year, count from compres
      where region="&amp;amp;regi" and disease="&amp;amp;dise"
      union
      select * from data.mtx3;
   quit;
 
   proc sql;
   create table sumup_count as 
   select distinct week, year , sum(count) as count
   from withoutState 
   group by week, year;
   quit;
   
   proc sort data=sumup_count;
   by week year; 
   run;
   
  
 *using the following proc transpose, we are gonna make the matrix;
   proc transpose data=sumup_count out=want (DROP=_LABEL_ AND _NAME_) prefix=year ;
   by week;
   id year;
   var count;
   run;

   data the_matrix_query_withnull;
   retain week year2001 year2002 year2003 year2004 year2005 year2006 year2007 year2008 year2009 year2010 year2011 year2012 year2013 year2014 year2015 year2016 year2017;
   set want;
   run;
  
    *the additional below data step is because we handel 
  the null and zero issue in the recomputation limits part. 
  in fact we need to put zero instead of null on missing value;
  data the_matrix_query;
   set the_matrix_query_withnull;
   if year2001=" " then year2001=0;
   if year2002=" " then year2002=0;
   if year2003=" " then year2003=0;
   if year2004=" " then year2004=0;
   if year2005=" " then year2005=0;
   if year2006=" " then year2006=0;
   if year2007=" " then year2007=0;
   if year2008=" " then year2008=0;
   if year2009=" " then year2009=0;
   if year2010=" " then year2010=0;
   if year2011=" " then year2011=0;
   if year2012=" " then year2012=0;
   if year2013=" " then year2013=0;
   if year2014=" " then year2014=0;
   if year2015=" " then year2015=0;
   if year2016=" " then year2016=0;
   if year2017=" " then year2017=0;
   run;

data statprocess;
	set the_matrix_query;
    avg=(sum(of year2007-year2016))/10;
 	x0=1;
 	x1=sin(2*3.14159*week/52);
	x2=cos(2*3.14159*week/52); 
 	x3=sin(4*3.14159*week/52); 
 	x4=cos(4*3.14159*week/52);
 	
run;

proc reg data=statprocess;
         model avg=x0;
         output out=trig_&amp;amp;regi._&amp;amp;dise. p=yhat r=e stdp=sd;
      run;
     

data _null_;
*set compres2 ; ---&amp;gt; here I removed setting onother data set because it goes through each row for each call execute analysis (there is a call execure outside to run the whole macro multiple times)
 %put &amp;amp;counter; 
if &amp;amp;counter= 1
then do;
  call execute('data all_results; set ');
end;
call execute('trig_'!!strip("&amp;amp;regi")!!'_'!!strip("&amp;amp;dise")!!'');
if &amp;amp;counter=73
then do;
%put "samira"; --&amp;gt; here I found out that "samira" repeated 73 times that mean something is wrong because 73 is the amount of rows that I have so it should just execute only one time.
call execute(';run;');
end;
run;

%mend;

 data _null_;
 set compres2;
 _n_=1;
 counter=_n_;
 call execute('%analysis('!!%str(strip(region))!!','!!%str(strip(disease))!!','!!strip(counter)!!');');
 run; 

proc print data=all_results(where=(week=3)); --&amp;gt; here I just got one row data. I expected to see all the outputs which come from each loop. 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I really appriciate all your helps.&lt;/P&gt;&lt;P&gt;Samira&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 19:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/perform-a-DO-loop-over-a-list-of-values-and-use-proc-sql-data/m-p/335381#M272196</guid>
      <dc:creator>samira</dc:creator>
      <dc:date>2017-02-23T19:15:52Z</dc:date>
    </item>
  </channel>
</rss>

