<?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: DO LOOP Macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508896#M1706</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thanks so much. Saved so much time. Now I can leave work early &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 19:22:38 GMT</pubDate>
    <dc:creator>craigwe85</dc:creator>
    <dc:date>2018-10-30T19:22:38Z</dc:date>
    <item>
      <title>DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508834#M1698</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the current code that goes to a weather website a downloads the data into SAS. The station macro, inputs the corresponding station id into the URL and then pulls the weather for that city. I will be inputting about 100+ cities. Instead of adding each individual station id to the macro below, is there a way to utilize a do loop macro that would go through a list of station id's that i will save as a sas dataset? i will be saving the new data set which will contain Station ID and City and calling it Weather_Stations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro station (stat=);

filename in url "http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&amp;amp;stationID=&amp;amp;stat&amp;amp;Year=2018&amp;amp;Month=10&amp;amp;Day=1&amp;amp;timeframe=2&amp;amp;submit=Download+Data";
filename out "%sysfunc(pathname(work))\data.csv";                                                                                                                 
                                                                                                                                                                  
data _null_;                                                                                                                                                      
  infile in;                                                                                                                                                      
  input;                                                                                                                                                          
  if _n_&amp;gt; 25;                                                                                                                                                     
  file out;                                                                                                                                                       
  put _infile_;                                                                                                                                                   
run;                                                                                                                                                              
                                                                                                                                                                  
PROC IMPORT OUT= WORK.data_&amp;amp;stat                                                                                                                                        
     DATAFILE= "%sysfunc(pathname(work))\data.csv"                                                                                                                
     DBMS=CSV REPLACE;                                                                                                                                            
RUN;
%mend;

%station (stat=52518);/*Sydgary*/
%station (stat=50149);/*Edmonton */
%station (stat=50837);/*Fort St.John*/
%station (stat=48369);/*Kelowananey*/
%station (stat=50620);/*Halifax*/
%station (stat=50309);/*Moncton*/
%station (stat=50068);/*Deer Lake*/
%station (stat=50089);/*St.Johns*/
%station (stat=50621);/*Chartown*/
%station (stat=51157);/*Montreal*/
%station (stat=26892);/*Quebec*/
%station (stat=51459);/*Toronto*/
%station (stat=49568);/*Ottawa */
%station (stat=54604);/*North Bay*/
%station (stat=27174);/*Winnipeg*/
%station (stat=28011);/*Regina*/
%station (stat=47707);/*Saskatoon*/
%station (stat=50430);/*Cal*/
%station (stat=51442);/*Vancouver*/
%station (stat=51337);/*Victoria*/&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508834#M1698</guid>
      <dc:creator>craigwe85</dc:creator>
      <dc:date>2018-10-30T17:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508839#M1700</link>
      <description>&lt;P&gt;You could store you station in a dataset and &lt;STRONG&gt;Call execute&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508839#M1700</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-30T17:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508840#M1701</link>
      <description>&lt;P&gt;Yes, if your city codes are in a SAS data set (and are stored as a character string named CITY_CODE), you can use CALL EXECUTE to call the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set have;
    call execute('%station(stat='||city_code||')');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508840#M1701</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-30T17:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508841#M1702</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; I am glad my brain is functioning alike you. Hopefully you bless me with your statistical skills and soon I can get good at those well. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508841#M1702</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-30T17:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508844#M1703</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; I am glad my brain is functioning alike you. Hopefully you bless me with your statistical skills and soon I can get good at those well. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm sure you will. It just takes time.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508844#M1703</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-30T17:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508849#M1705</link>
      <description>&lt;P&gt;Try this example:&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;
/* Set up test data */
/* this would be your dataset containing your station Ids */
data test ;
	do station_id=1000 to 1020 by 3 ;
		output ;
	end ;
run ;


/* Create macro to loop through the station Ids */
/* Pass in the station ID dataset and the variable name containing the station Ids */
%macro loop(inputDataset,stationVar) ;
	%put &amp;amp;inputDataset= &amp;amp;stationVar= ;
	/* 
	Datastep will create multiple macro variables named station_id&amp;lt;n&amp;gt; 
	where &amp;lt;n&amp;gt; is a number 1+, and containing the station Ids
	Create a count of all station Ids
	*/
	data _null_ ;
		set &amp;amp;inputDataset ;
		put _all_ ;
		
		call symput("station_id"!!left(putn(_n_,"10.")),putn(&amp;amp;stationVar,"10.")) ;
		call symput("count",putn(_n_,"10.")) ;
	run ;
	
	/* 
	Loop through all the macro variables printinng their values
	Note you would call your station macro inside this loop 
	*/
	%do i=1 %to &amp;amp;count ;
		%put &amp;amp;count &amp;amp;i &amp;amp;&amp;amp;station_id&amp;amp;i ;
		
	%end ;

%mend ;

%loop(test,station_id) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508849#M1705</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2018-10-30T17:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508896#M1706</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thanks so much. Saved so much time. Now I can leave work early &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 19:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/508896#M1706</guid>
      <dc:creator>craigwe85</dc:creator>
      <dc:date>2018-10-30T19:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/573967#M12608</link>
      <description>&lt;P&gt;Sorry I realize this post is old,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however I am still using this technique and was wondering if it were possible to add more variables to the call execute function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so I can create unique tables names and add an additional where statement if needed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 18:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/573967#M12608</guid>
      <dc:creator>craigwe85</dc:creator>
      <dc:date>2019-07-16T18:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/573977#M12610</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;Just make sure to generate valid SAS code.&lt;/P&gt;
&lt;P&gt;Using the CAT... series of functions can help.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(var1=,var2=,var3=);
 .... 
%mend;

data _null_;
  set mydata ;
  call execute(cats('%nrstr(%mymacro)','(var1=',var1,',var2=',var2,',var3=',var3,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 19:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-LOOP-Macro/m-p/573977#M12610</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-16T19:18:51Z</dc:date>
    </item>
  </channel>
</rss>

