<?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 have option to output 2 datasets using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778824#M247963</link>
    <description>&lt;P&gt;What you're asking for is fairly straightforward but not simple for a beginner. &lt;BR /&gt;First make sure your macro works for the most basic case, a single value. As posted it would not work. &lt;BR /&gt;&lt;BR /&gt;Can you confirm your requirements as well, specifically how you want ALL to be handled. &lt;BR /&gt;&lt;BR /&gt;Macro that will split a data set based on a variable value.&lt;BR /&gt;If multiple values are provided, then multiple data sets are generated.&lt;BR /&gt;If a single value is provided then one data set is generated.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If the key word ALL is provided, a data set is created for each unique level of Origin&amp;nbsp;&lt;STRONG&gt;or&lt;/STRONG&gt; a single data set is created?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&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;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have an input dataset (sashelp.class) and&amp;nbsp; want to make a output named a1 and then input as a1 and make a2 dataset.&lt;/P&gt;
&lt;P&gt;My concern is i want to make a macro variable where user can either output a1 or a2 or both a1 and a2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help on this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;something like below but my condition as above, i create a1 and from a1 i create a2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro RRR(value);
Data  tbl_&amp;amp;Value. ;
SET  SASHELP.CARS(where=(origin='&amp;amp;Value."));
Run;
%Mend RRR:
%RRR(value='Asia');
%RRR(value='Europe');
%RRR(value='All');/*I know it is not good code and my question is how should it be written*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Nov 2021 16:12:15 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-11-05T16:12:15Z</dc:date>
    <item>
      <title>How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778788#M247941</link>
      <description>&lt;P&gt;I have an input dataset (sashelp.class) and&amp;nbsp; want to make a output named a1 and then input as a1 and make a2 dataset.&lt;/P&gt;
&lt;P&gt;My concern is i want to make a macro variable where user can either output a1 or a2 or both a1 and a2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help on this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;something like below but my condition as above, i create a1 and from a1 i create a2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro RRR(value);
Data  tbl_&amp;amp;Value. ;
SET  SASHELP.CARS(where=(origin='&amp;amp;Value."));
Run;
%Mend RRR:
%RRR(value='Asia');
%RRR(value='Europe');
%RRR(value='All');/*I know it is not good code and my question is how should it be written*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Nov 2021 14:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778788#M247941</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2021-11-05T14:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778806#M247947</link>
      <description>&lt;P&gt;So first of all, this code you present won't work as written. Do you see how in one place you use a single quote and finish the text with a double quote?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%RRR(value='Asia');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you really want&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%RRR(value=Asia)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why? Because if macro variable &amp;amp;VALUE is assigned the value of 'Asia' in quotes, then when you execute the code, you get&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data  tbl_'Asia';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this isn't legitimate SAS syntax and won't work — can you see why it won't work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any event, first you need to clean all of this up and get your macro working with one parameter, before adding an option to output 2 data sets. No point adding more "features" to a macro that doesn't work.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 15:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778806#M247947</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-05T15:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778814#M247955</link>
      <description>&lt;P&gt;No, I want to have in macro call either to call a1 as output&amp;nbsp; or a2 as output dataset or both, but as i said i get a2 datset from a1&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 15:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778814#M247955</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2021-11-05T15:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778818#M247959</link>
      <description>&lt;P&gt;Show us a working macro without this option, before we try to incorporate this other option.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 15:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778818#M247959</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-05T15:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778824#M247963</link>
      <description>&lt;P&gt;What you're asking for is fairly straightforward but not simple for a beginner. &lt;BR /&gt;First make sure your macro works for the most basic case, a single value. As posted it would not work. &lt;BR /&gt;&lt;BR /&gt;Can you confirm your requirements as well, specifically how you want ALL to be handled. &lt;BR /&gt;&lt;BR /&gt;Macro that will split a data set based on a variable value.&lt;BR /&gt;If multiple values are provided, then multiple data sets are generated.&lt;BR /&gt;If a single value is provided then one data set is generated.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If the key word ALL is provided, a data set is created for each unique level of Origin&amp;nbsp;&lt;STRONG&gt;or&lt;/STRONG&gt; a single data set is created?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&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;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have an input dataset (sashelp.class) and&amp;nbsp; want to make a output named a1 and then input as a1 and make a2 dataset.&lt;/P&gt;
&lt;P&gt;My concern is i want to make a macro variable where user can either output a1 or a2 or both a1 and a2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help on this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;something like below but my condition as above, i create a1 and from a1 i create a2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro RRR(value);
Data  tbl_&amp;amp;Value. ;
SET  SASHELP.CARS(where=(origin='&amp;amp;Value."));
Run;
%Mend RRR:
%RRR(value='Asia');
%RRR(value='Europe');
%RRR(value='All');/*I know it is not good code and my question is how should it be written*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 16:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778824#M247963</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-05T16:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778915#M248010</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chk(outp=);
%if &amp;amp;outp=a1 %then %do;
data inc;
    set sashelp.class;
	............
run;
%end;

%if &amp;amp;outp=a2 %then %do;
data inb;
   set inc;
   ..........
run;
%end;

%mend;

**Want to call any one of the below;
%chk(outp=a1);
or
%chk(outp=a2);
or 
%chk(outp=a1 a2);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Nov 2021 09:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778915#M248010</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2021-11-06T09:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778924#M248014</link>
      <description>&lt;P&gt;How about this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chk(outp=); /* Valid values for OUTP= are 1 or 2 or BOTH */
	%if &amp;amp;outp=1 %then %do;
		data inc;
			set sashelp.class;
		run;
	%end;
	%else %if &amp;amp;outp=2 %then %do;
		data inb;
			set sashelp.class;	
		run;
	%end;
	%else %if &amp;amp;outp=BOTH %then %do;
		data inb;
			set sashelp.class;	
		run;
		data inc;
			set sashelp.class;
		run;
	%end;
%mend;

options mprint;
%chk(outp=1)
%chk(outp=2)
%chk(outp=BOTH)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or even simpler&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chk(outp=); /* Valid values for OUTP= are a1 or a2 or a1 a2 */
	%if %index(&amp;amp;outp,a1) %then %do;
		data inc;
			set sashelp.class;
		run;
	%end;
	%if %index(&amp;amp;outp,a2) %then %do;
		data inb;
			set sashelp.class;	
		run;
	%end;
%mend;

options mprint;
%chk(outp=a1)
%chk(outp=a2)
%chk(outp=a1 a2)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Nov 2021 11:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778924#M248014</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-06T11:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can i have option to output 2 datasets using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778943#M248026</link>
      <description>&lt;P&gt;Before creating a macro to GENERATE SAS code you need to know what SAS code you want to generate.&lt;/P&gt;
&lt;P&gt;So please show the code you want to run for each of the three macro calls you have.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please write it out yourself before clicking on the SPOILER link below.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* %RRR(value='Asia'); */
data tbl_asia;
  set sashelp.cars;
  where origin="Asia";
run;
/* %RRR(value='Europe'); */
data tbl_europe;
  set sashelp.cars;
  where origin="Europe";
run;
/* %RRR(value='All'); */
data tbl_all;
  set sashelp.cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Once you can make the code for the three cases then you can check and see if there is a pattern in the code that might make it possible for you to use macro logic to generate the proper code based on the input parameters you decide to create.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Nov 2021 16:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-have-option-to-output-2-datasets-using-macro/m-p/778943#M248026</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-06T16:20:24Z</dc:date>
    </item>
  </channel>
</rss>

