<?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: how to run the same SAS code for different datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562906#M157752</link>
    <description>&lt;P&gt;Here's one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis(dsnames);
    %do i=1 %to %sysfunc(countw(&amp;amp;dsnames));
        %let thisname=%scan(&amp;amp;dsnames,&amp;amp;i,%str( ));
        data xx&amp;amp;i;
            set &amp;amp;thisname;
            ...
         run;
         proc freq data=xx&amp;amp;i;
              tables var var2 var3;
         run;
    %end;
%mend;
%dothis(dataset1 dataset2 dataset3) /* Add as many data set names inside the parenthesis as needed */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 31 May 2019 16:48:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-05-31T16:48:23Z</dc:date>
    <item>
      <title>how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562904#M157751</link>
      <description>&lt;P&gt;Hello, I'm don't know SAS Macro and appreciate if you help me with the below questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 20 datasets with the same set of variables.&amp;nbsp;I need to run a set of SAS&amp;nbsp;&amp;nbsp;statements for each data set. Here are an example of each statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset1......dataset20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1- recode and define the variables&amp;nbsp;&lt;/P&gt;&lt;P&gt;data XX1;&lt;/P&gt;&lt;P&gt;set dataet1;&lt;/P&gt;&lt;P&gt;if var1 in ('A', 'B', 'C') then Var1=1; else Var1=0;&lt;/P&gt;&lt;P&gt;if var2 in ('D', 'E', 'F') then Var2=1; else Var2=0;&lt;/P&gt;&lt;P&gt;if Var3 .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2- estimate freq or mean..... of a set of variables for each data set:&lt;/P&gt;&lt;P&gt;proc freq data=XX1; tables var1 var2 var3 ; run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 16:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562904#M157751</guid>
      <dc:creator>mamin088</dc:creator>
      <dc:date>2019-05-31T16:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562906#M157752</link>
      <description>&lt;P&gt;Here's one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis(dsnames);
    %do i=1 %to %sysfunc(countw(&amp;amp;dsnames));
        %let thisname=%scan(&amp;amp;dsnames,&amp;amp;i,%str( ));
        data xx&amp;amp;i;
            set &amp;amp;thisname;
            ...
         run;
         proc freq data=xx&amp;amp;i;
              tables var var2 var3;
         run;
    %end;
%mend;
%dothis(dataset1 dataset2 dataset3) /* Add as many data set names inside the parenthesis as needed */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2019 16:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562906#M157752</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-31T16:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562907#M157753</link>
      <description>&lt;P&gt;Why not just run it once for all 20 datasets?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XX1;
  set dataset2 ds2 dataset3 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2019 16:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562907#M157753</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-31T16:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562912#M157754</link>
      <description>&lt;P&gt;A non-macro solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
    set dataset1 dataset2 dataset3 /* Add as many datasets here as needed */
         indsname=dsname;
    whichdsn=dsname;
run;
proc freq data=all;
    by whichdsn;
    table var1 var2 var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2019 16:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562912#M157754</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-31T16:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562917#M157757</link>
      <description>Thank you so much for the quick reply! As I said I'm very new in SAS macro, so would you please walk me through the code a little bit?</description>
      <pubDate>Fri, 31 May 2019 17:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562917#M157757</guid>
      <dc:creator>mamin088</dc:creator>
      <dc:date>2019-05-31T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562925#M157761</link>
      <description>I did that once before for another study and it was very time-consuming. Also, it is subject to higher errors!</description>
      <pubDate>Fri, 31 May 2019 17:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562925#M157761</guid>
      <dc:creator>mamin088</dc:creator>
      <dc:date>2019-05-31T17:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562930#M157763</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276266"&gt;@mamin088&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you so much for the quick reply! As I said I'm very new in SAS macro, so would you please walk me through the code a little bit?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First try the non-macro code I posted in message 4 of this thread.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 17:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562930#M157763</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-31T17:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562932#M157764</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276266"&gt;@mamin088&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I did that once before for another study and it was very time-consuming. Also, it is subject to higher errors!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Errors perhaps of different variable types because attention was not paid when reading the variables to begin with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc IMPORT is &lt;STRONG&gt;not your friend&lt;/STRONG&gt; when reading multiple files of similar structure that should have the same variables and properties for the variables. It makes a different set of guesses for each an every file imported.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 17:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562932#M157764</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-31T17:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562938#M157766</link>
      <description>Not really! mostly because of typing and repeating! Besides, if you need to change one thing in the statement you will have to change it for all dataset!</description>
      <pubDate>Fri, 31 May 2019 17:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562938#M157766</guid>
      <dc:creator>mamin088</dc:creator>
      <dc:date>2019-05-31T17:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562954#M157770</link>
      <description>&lt;P&gt;Here's a short tutorial I wrote that illustrates how to turn a program into a macro, step by step:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here's a tutorial from UCLA that will help:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&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;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276266"&gt;@mamin088&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I'm don't know SAS Macro and appreciate if you help me with the below questions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 20 datasets with the same set of variables.&amp;nbsp;I need to run a set of SAS&amp;nbsp;&amp;nbsp;statements for each data set. Here are an example of each statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset1......dataset20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1- recode and define the variables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data XX1;&lt;/P&gt;
&lt;P&gt;set dataet1;&lt;/P&gt;
&lt;P&gt;if var1 in ('A', 'B', 'C') then Var1=1; else Var1=0;&lt;/P&gt;
&lt;P&gt;if var2 in ('D', 'E', 'F') then Var2=1; else Var2=0;&lt;/P&gt;
&lt;P&gt;if Var3 .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2- estimate freq or mean..... of a set of variables for each data set:&lt;/P&gt;
&lt;P&gt;proc freq data=XX1; tables var1 var2 var3 ; run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 18:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562954#M157770</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-31T18:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to run the same SAS code for different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562964#M157775</link>
      <description>Thank you so much!</description>
      <pubDate>Fri, 31 May 2019 19:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-the-same-SAS-code-for-different-datasets/m-p/562964#M157775</guid>
      <dc:creator>mamin088</dc:creator>
      <dc:date>2019-05-31T19:01:03Z</dc:date>
    </item>
  </channel>
</rss>

