<?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: Pass one by one different values into a script file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/623114#M183371</link>
    <description>&lt;P&gt;A macro will allow you to create a more sophisticated program.&amp;nbsp; You can use macro logic to make adjustments to the code being generated based on values that passed to it. You can use local macro variables to reduce risk of confusion caused by old macro variable values retaining values from previous runs. etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is something you need to do repeatedly you can store the macro code into your autocall library and skip the step of needing to %INCLUDE main code.&amp;nbsp; You just need to write the macro call.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Feb 2020 16:50:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-07T16:50:02Z</dc:date>
    <item>
      <title>Pass one by one different values into a script file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622139#M182994</link>
      <description>&lt;DIV&gt;&lt;SPAN&gt;Greetings.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;I have one script/program file full of steps (let's call it "script.sas").&amp;nbsp; At the beginning of the script I place a macro variable, which is referred to throughout the script.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;%let item=a001;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;In the above macro variable, the value "a001" is one of many, let's say 100 different values in total.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;i.e.,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;a001&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;a002&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;a003&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;a100&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Is there any way of passing all these macro variable values from a batch file?&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Something along the lines of:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;%include "a001" ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;%include "a002" ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;%include "a003" ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Another idea might be to use the file name, so change:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;script.sas --&amp;gt; a001.sas&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Create a different file for each macro variable value.&amp;nbsp; Then tell SAS to use the name of the script as the macro variable value?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Any suggestions greatly appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Nicholas Kormanik&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622139#M182994</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2020-02-04T08:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Pass one by one different values into a script file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622140#M182995</link>
      <description>&lt;P&gt;If you want to feed values from outside to a SAS program, consider using environment variables:&lt;/P&gt;
&lt;PRE&gt;export SAS_VALUE1=a001
/sasconf/Lev1/SASApp/BatchServer/sasbatch.sh $HOME/sas/script.sas&lt;/PRE&gt;
&lt;P&gt;In your program script.sas you would do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let item=%sysget(SAS_VALUE1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622140#M182995</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T08:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Pass one by one different values into a script file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622194#M183017</link>
      <description>&lt;P&gt;I'm not understanding.&amp;nbsp; Do you want to create one macro variable with a list of values, or do you want to create several macro variables?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Environment variables are an option, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;mentioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to do it is to have a program MakeGlobalMacVars.sas.&amp;nbsp; That program could be just a bunch of %LET statements.&amp;nbsp; And your main program&amp;nbsp; could %include&amp;nbsp;MakeGlobalMacVars.sas .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to do it would be to make a SAS dataset (or database table, or text file) that stores name-value pairs (macro variable name, and value).&amp;nbsp; Then your main program could read that dataset, and use CALL SYMPUTX to generate the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or search for papers/books on data-driven programming, e.g. Troy Hughes' book:&amp;nbsp;&lt;A href="https://www.amazon.com/SAS-Data-Driven-Development-Abstract-Functionality/dp/1726497739" target="_blank"&gt;https://www.amazon.com/SAS-Data-Driven-Development-Abstract-Functionality/dp/1726497739&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 14:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622194#M183017</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-02-04T14:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Pass one by one different values into a script file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622220#M183025</link>
      <description>&lt;P&gt;So you have set of values you want to use, let's assume you have those values in a dataset named HAVE with a variable named ITEM.&lt;/P&gt;
&lt;P&gt;You could use that dataset to generate a program that looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let item=a001;
%include "script.sas";
%let item=s002;
%include "script.sas";
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That is simple to do.&amp;nbsp; Personally I prefer to do it by writing the lines of code to a file and including that file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set have;
  put '%let ' item= ';';
  put '%include "script.sas";';
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sounds like you are close to converting your program into a macro.&amp;nbsp; Just wrap the current connect with a %MACRO and %MEND statements.&amp;nbsp; Let's say we call the macro SCRIPT.&amp;nbsp; So you could copy your existing program into a new program we could call macro_script.sas.&amp;nbsp; It would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro script(item);
.... lines from your program after the %LET ITEM statement ...
%mend script;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And now the lines of code you need to generate are like this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "macro_script.sas";
%script(item=a001);
%script(item=a002);
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 15:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622220#M183025</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T15:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Pass one by one different values into a script file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622976#M183301</link>
      <description>&lt;P&gt;The simpler way seems to work fine.&amp;nbsp; Thanks much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why would you choose to go the more complicated route?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 09:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/622976#M183301</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2020-02-07T09:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pass one by one different values into a script file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/623114#M183371</link>
      <description>&lt;P&gt;A macro will allow you to create a more sophisticated program.&amp;nbsp; You can use macro logic to make adjustments to the code being generated based on values that passed to it. You can use local macro variables to reduce risk of confusion caused by old macro variable values retaining values from previous runs. etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is something you need to do repeatedly you can store the macro code into your autocall library and skip the step of needing to %INCLUDE main code.&amp;nbsp; You just need to write the macro call.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-one-by-one-different-values-into-a-script-file/m-p/623114#M183371</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T16:50:02Z</dc:date>
    </item>
  </channel>
</rss>

