<?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 Macro-data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590592#M169051</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi i have a problem inserting the data set into the macro command definition. I don't know how to call a specific numeric variable. Data set has 4 columns, 2 are text and the last 2 are numeric.&amp;nbsp;I want to call a text variable to put it in a logical expression with% LENGHT.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is the code. Below is the data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SAS 9.4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;561 %macro make(podaci,County);&lt;BR /&gt;562 %if %length(&amp;amp;County) gt 8 %then&lt;BR /&gt;563 %let County = %substr(&amp;amp;County,1,8);&lt;BR /&gt;564 filename &amp;amp;podaci "&amp;amp;County";&lt;BR /&gt;565 %mend make;&lt;BR /&gt;566 %make(prog.podaci18)&lt;BR /&gt;ERROR: Invalid logical name.&lt;BR /&gt;ERROR: Error in the FILENAME statement.&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>Sat, 21 Sep 2019 12:24:00 GMT</pubDate>
    <dc:creator>malov0610</dc:creator>
    <dc:date>2019-09-21T12:24:00Z</dc:date>
    <item>
      <title>Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590592#M169051</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi i have a problem inserting the data set into the macro command definition. I don't know how to call a specific numeric variable. Data set has 4 columns, 2 are text and the last 2 are numeric.&amp;nbsp;I want to call a text variable to put it in a logical expression with% LENGHT.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is the code. Below is the data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SAS 9.4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;561 %macro make(podaci,County);&lt;BR /&gt;562 %if %length(&amp;amp;County) gt 8 %then&lt;BR /&gt;563 %let County = %substr(&amp;amp;County,1,8);&lt;BR /&gt;564 filename &amp;amp;podaci "&amp;amp;County";&lt;BR /&gt;565 %mend make;&lt;BR /&gt;566 %make(prog.podaci18)&lt;BR /&gt;ERROR: Invalid logical name.&lt;BR /&gt;ERROR: Error in the FILENAME statement.&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>Sat, 21 Sep 2019 12:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590592#M169051</guid>
      <dc:creator>malov0610</dc:creator>
      <dc:date>2019-09-21T12:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590593#M169052</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291547"&gt;@malov0610&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I have a problem inserting the data set into the macro command definition. &lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This first sentence of yours does not really make sense to me. More information is needed. What does "insert" a data set mean? How do you want to insert this data set? Where do you want to insert this data set? What do these macro variables have to do with this data set? What should the result of the code be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide a lot more explanation. Please show us the code you have tried, even if it doesn't work.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 12:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590593#M169052</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-21T12:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590594#M169053</link>
      <description>&lt;P&gt;I want a macro command that I will use on the data set I have attached. I want the macro command it would create to take values ​​from a Country variable that contains the names of the municipalities and put them in an expression next to the% LENGHT statement.&lt;/P&gt;&lt;P&gt;%macro make(podaci,County);&lt;BR /&gt;%if %length(&amp;amp;County) gt 8 %then&lt;BR /&gt;%let County = %substr(&amp;amp;County,1,8);&lt;BR /&gt;filename &amp;amp;podaci "&amp;amp;County";&lt;BR /&gt;%mend make;&lt;BR /&gt;%make(prog.podaci18)&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 12:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590594#M169053</guid>
      <dc:creator>malov0610</dc:creator>
      <dc:date>2019-09-21T12:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590597#M169056</link>
      <description>&lt;P&gt;Macro commands operate on text and generate text.&amp;nbsp; &amp;nbsp;Normally you use them to generate text that SAS can interpret as code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So show the SAS code (not macro code) that you want to generate.&amp;nbsp; Explain what parts of that code needs to vary and explain how it should vary and logic needed. Then perhaps you can start to write a macro that can generate the code you need.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 12:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590597#M169056</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-21T12:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590599#M169058</link>
      <description>&lt;P&gt;okay, i'm curious when i create macros, the parameters in brackets are whether they refer to variables within the data set&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 13:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590599#M169058</guid>
      <dc:creator>malov0610</dc:creator>
      <dc:date>2019-09-21T13:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590604#M169063</link>
      <description>&lt;P&gt;The parameters to a macro just populate local macro variables to the macro.&amp;nbsp; So in the code of the macro you use them the same as any other macro variable.&amp;nbsp; Say you had this code to run PROC FREQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=prodaci18;
&amp;nbsp;&amp;nbsp;tables&amp;nbsp;country ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you wanted to make a way to do the same thing for a different variable in the dataset.&amp;nbsp; First create a macro variable to hold the name of the variable and then replace the name of the variable with the reference to the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varname=country;
proc freq data=prodaci18;
&amp;nbsp;&amp;nbsp;tables&amp;nbsp;&amp;amp;varname. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can convert this to a macro that has a parameter named varname.&amp;nbsp; Now you can pass in the name of the variable to use when generating the code when you call the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run_freq(varname);
proc freq data=prodaci18;
&amp;nbsp;&amp;nbsp;tables&amp;nbsp;&amp;amp;varname. ;
run;
%mend run_freq ;

%run_freq(varname=country);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that all three of these code blocks run the exact same SAS code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 13:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590604#M169063</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-21T13:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590607#M169066</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you very much for your help. I did it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 13:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590607#M169066</guid>
      <dc:creator>malov0610</dc:creator>
      <dc:date>2019-09-21T13:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590609#M169068</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291547"&gt;@malov0610&lt;/a&gt;&amp;nbsp;, it seems you are confused how to use macros.&lt;/P&gt;
&lt;P&gt;First semantics: The next I use to call as MACRO PROGRAM which maybe you call as MACRO COMMAND:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro &amp;lt;macro_name&amp;gt; (...argumants...);
   ....
%mend &amp;lt;macro_name&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Argument may be positional or named:&lt;/P&gt;
&lt;PRE&gt;%macro &amp;lt;macro_name&amp;gt; (arg1 , arg2 , named1=... , named2= ...);&lt;/PRE&gt;
&lt;P&gt;You defined 2 positional arguments in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro make(podaci,County);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then when you invoke the macro program/command you have to supply those two arguments.&lt;/P&gt;
&lt;P&gt;writing&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;%make(prog.podaci18)&lt;/SPAN&gt;&lt;/STRONG&gt;&amp;nbsp;- miss ';' at the end of the statement, and what is&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;prog.podaci18&lt;/STRONG&gt;&amp;nbsp;?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;those are no the arguments you have to supply ! It seems more as a sas dataset name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code between&amp;nbsp;&lt;STRONG&gt;%macro&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;%mend&lt;/STRONG&gt; should contain the sas code that do what you want,&lt;/P&gt;
&lt;P&gt;using macro variables, the arguments you supplied, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro add(varname, vvalue);
data want;
   set have end=eof;
       output;
        if eof then do;   /* adding new obs */
           &amp;amp;varname = &amp;amp;vvalue;    /*for numeric variable , OR 
           &amp;amp;varname = "&amp;amp;vvalue" ;  &amp;lt;&amp;lt; for char type variable */
run;
%mend;

%add(&amp;lt;new_ID&amp;gt;, &amp;lt;it value&amp;gt;);

           &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 13:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590609#M169068</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-09-21T13:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro-data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590612#M169070</link>
      <description>&lt;P&gt;&lt;BR /&gt;I am a little bit. I didn't understand where to define the data set. But thank you for your help&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 13:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-data-set/m-p/590612#M169070</guid>
      <dc:creator>malov0610</dc:creator>
      <dc:date>2019-09-21T13:45:43Z</dc:date>
    </item>
  </channel>
</rss>

