<?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 can I change this macro to create all the variables in one data set? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/933437#M367114</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Sun, 23 Jun 2024 03:09:23 GMT</pubDate>
    <dc:creator>kyle234</dc:creator>
    <dc:date>2024-06-23T03:09:23Z</dc:date>
    <item>
      <title>How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932635#M366889</link>
      <description>&lt;P&gt;How can I change this macro to create all the variables in one data set? I want&amp;nbsp; First_ADD and Second_ADD in the out flag data set. I want to do this for multiple varibles using the macro but it keeps overwriting itself and keeping the last flag that was created by the macro. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MACRO FLAG(VAR1,VAR2,FLAGNAME);&lt;BR /&gt;DATA FLAG;&lt;BR /&gt;SET RULE1;&lt;BR /&gt;&amp;amp;FLAGNAME=0;&lt;BR /&gt;DO _N_=1 to countw(&amp;amp;VAR1,',') while(&amp;amp;FLAGNAME=0);&lt;BR /&gt;word=scan(&amp;amp;VAR1,_N_,',');&lt;BR /&gt;if word=' ' then continue;&lt;BR /&gt;if indexw(trim(&amp;amp;VAR2),trim(word),',') then&lt;BR /&gt;&amp;amp;FLAGNAME=1;&lt;BR /&gt;end;&lt;BR /&gt;drop word;&lt;BR /&gt;run;&lt;BR /&gt;%MEND FLAG;&lt;/P&gt;
&lt;P&gt;%FLAG(Addresses1,Addresses2,First_ADD);&lt;BR /&gt;%FLAG(Addresses1,Addresses3,Second_ADD);&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 16:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932635#M366889</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-06-17T16:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932648#M366890</link>
      <description>&lt;P&gt;Not sure what you want to get, but based on my best guess, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO FLAG(IN, OUT, VAR1,VAR2,FLAGNAME);
DATA &amp;amp;out.;
SET &amp;amp;in.;
&amp;amp;FLAGNAME=0;
DO _N_=1 to countw(&amp;amp;VAR1,',') while(&amp;amp;FLAGNAME=0);
word=scan(&amp;amp;VAR1,_N_,',');
if word=' ' then continue;
if indexw(trim(&amp;amp;VAR2),trim(word),',') then
&amp;amp;FLAGNAME=1;
end;
drop word;
run;
%MEND FLAG;

%FLAG(RULE1,RULE2,Addresses1,Addresses2,First_ADD);
%FLAG(RULE2,FLAG,Addresses1,Addresses3,Second_ADD);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 14:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932648#M366890</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-06-17T14:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932657#M366894</link>
      <description>&lt;P&gt;What are "all the variables"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you have version of the code that created an "all the variables" without any macro coding at all? That is the first step.&lt;/P&gt;
&lt;P&gt;An example data set and the result with "all the variables" created for that example would be very helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: if&amp;nbsp; you want to pass a list of values as a parameter do not use COMMAS as the macro processor will want to use them as delimiters between different parameters. Use a space and then specify the space in the SCAN and COUNTW function as a delimiter, or some other character like a |&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 14:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932657#M366894</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-17T14:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932693#M366900</link>
      <description>&lt;P&gt;Thank you! So i want both first_add and second_add to be in the out data set&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 16:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932693#M366900</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-06-17T16:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932694#M366901</link>
      <description>&lt;P&gt;Sorry should have been more specific.&amp;nbsp;I want&amp;nbsp; First_ADD and Second_ADD in the out flag data set.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 16:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932694#M366901</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-06-17T16:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932697#M366902</link>
      <description>&lt;P&gt;One simple change is to NOT hardcode the names of the datasets.&amp;nbsp; Instead make those as parameters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO FLAG(in,out,VAR1,VAR2,FLAGNAME);
DATA &amp;amp;out;
SET &amp;amp;in;
&amp;amp;FLAGNAME=0;
DO _N_=1 to countw(&amp;amp;VAR1,',') while(&amp;amp;FLAGNAME=0);
word=scan(&amp;amp;VAR1,_N_,',');
if word=' ' then continue;
if indexw(trim(&amp;amp;VAR2),trim(word),',') then
&amp;amp;FLAGNAME=1;
end;
drop word;
run;
%MEND FLAG;

%FLAG(RULE1,ADD1,Addresses1,Addresses2,First_ADD);
%FLAG(ADD1 ,ADD2,Addresses1,Addresses3,Second_ADD);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also add a %DO loop to generate separate blocks of code for each variable so you can do it in a single data step.&amp;nbsp; So instead of passing in one VAR2 name you could pass in a list.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you want the flag names to be generated?&amp;nbsp; Do you want to also pass in a list?&lt;/P&gt;
&lt;P&gt;Or perhaps it would be easier to just append a suffix to the name of the VAR2 variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO FLAG(in,out,VAR1,VARNAMEs,suffix);
%local i var2 flagname;
DATA &amp;amp;out;
  SET &amp;amp;in;
%do i=1 %to %sysfunc(countw(&amp;amp;varnames,%str( )));
  %let var2=%scan(&amp;amp;varnames,&amp;amp;i,%str( ));
  %let flagname=&amp;amp;var2._&amp;amp;suffix;

  &amp;amp;FLAGNAME=0;
  DO _N_=1 to countw(&amp;amp;VAR1,',') while(&amp;amp;FLAGNAME=0);
  word=scan(&amp;amp;VAR1,_N_,',');
  if word=' ' then continue;
  if indexw(trim(&amp;amp;VAR2),trim(word),',') then
  &amp;amp;FLAGNAME=1;
  end;
%end;
  drop word;
run;
%MEND FLAG;

options mprint;
%FLAG(RULE1,ADD,Addresses1,Addresses2 Address3,ADD);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that is not what you want then you probably need to supply some example input and the output you want from that input to help explain what you are doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 16:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/932697#M366902</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-17T16:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/933436#M367113</link>
      <description>&lt;P&gt;Thank you! That did help me fir=gure it out&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2024 03:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/933436#M367113</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-06-23T03:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change this macro to create all the variables in one data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/933437#M367114</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2024 03:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-this-macro-to-create-all-the-variables-in-one/m-p/933437#M367114</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-06-23T03:09:23Z</dc:date>
    </item>
  </channel>
</rss>

