<?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 NOT manually type all 50 values in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748632#M235120</link>
    <description>&lt;P&gt;Create a dataset with locations, and use CALL EXECUTE from that (the macro for a single location should have code to start a new page):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=have (keep=location)
  out=control
  nodupkey
;
by location;
run;

ods rtf .....;

data _null_;
set control;
call execute(cats('%nrstr(%location(location=',location,'))'));
run;

ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jun 2021 07:56:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-06-17T07:56:30Z</dc:date>
    <item>
      <title>how to NOT manually type all 50 values in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748582#M235090</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I have a dataset with 50 different geographic locations (variable "COUNTRY") I need to subset.&amp;nbsp; &amp;nbsp; Rather than creating a macro and manually calling all 50 locations, I was wondering if there's an efficient process where I can collect all the values of variable "COUNTRY" and produce ONE rtf output (each page will have different locations)?&amp;nbsp; I know you can use BY statement in proc report but my original program is a bit more complex than the example shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro location(location=);
proc sort data=cars (keep=model color country);
   by country;
   where country=&amp;amp;location;
run;

proc sql;
	select (strip(put(count(distinct model), best.))) into :var1 from cars;
quit;

%put &amp;amp;var1;
 

ods rtf "c:/desktop/carmodel.rtf";
title1= "2021 car models in &amp;amp;location";
proc report data=cars;
    column model ;
    define model display "&amp;amp;location (&amp;amp;var1)";
run;

%mend location;

%location (location='USA');
%location (location='MEX');
%location (location='CHN');
%location (location='CAN');
%location (location='JAP');
%location (location='KOR');
%location (location='RUS');
%location (location='AFR');
%location (location='AUS');
%location (location='PR');
%location (location='BRA');
%location (location='IND');
%location (location='AMS');
%location (location='ENG');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jun 2021 00:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748582#M235090</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-06-17T00:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to NOT manually type all 50 values in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748589#M235092</link>
      <description>&lt;P&gt;I think this is the second time you have said you have to "subset" something.&lt;/P&gt;
&lt;P&gt;When you use a phrase like "manually calling all 50 locations" I think you a misusing "subset".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about providing some example data and your "original program" that is more complex. It may be that your complex program is part of the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And there are probably a hundred programs here that show how to do this by pulling all the distinct values from a data set into a macro variable then using them.&lt;/P&gt;
&lt;PRE&gt;%macro dummy;

proc sql noprint;
   select distinct origin into :originlist separated by ' '
   from sashelp.cars
   ;
quit;

ods rtf file="c:\desktop\carmodel.rtf";

%do i = 1 %to %sysfunc(countw(&amp;amp;originlist.));

   %let location = %scan(&amp;amp;originlist.,&amp;amp;i);
   proc sql noprint;
   	select count(*) into :var1 
      from (select distinct model from sashelp.cars
           where origin = "&amp;amp;location." )
      
      ;
   quit;

   %put &amp;amp;var1;
    

   proc report data=sashelp.cars;
       where origin = "&amp;amp;location.";
       column model ;
       define model /display "&amp;amp;location. (&amp;amp;var1)";
   run;

%end; /* end the loop I*/

ods rtf close;
%mend;

%dummy;


&lt;/PRE&gt;
&lt;P&gt;What you were attempting was going to overwrite the output rtf file. You need to make sure if want one document that the ods rtf/ ods rtf close sandwiches ALL the output calls you want to make.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first sql builds a list and the %do loop shows how to iterate over each value in that list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 01:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748589#M235092</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-17T01:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to NOT manually type all 50 values in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748632#M235120</link>
      <description>&lt;P&gt;Create a dataset with locations, and use CALL EXECUTE from that (the macro for a single location should have code to start a new page):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=have (keep=location)
  out=control
  nodupkey
;
by location;
run;

ods rtf .....;

data _null_;
set control;
call execute(cats('%nrstr(%location(location=',location,'))'));
run;

ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 07:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748632#M235120</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-17T07:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to NOT manually type all 50 values in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748661#M235140</link>
      <description>&lt;P&gt;As soon as you start specifying that the solution MUST include a macro, you lose the opportunity to find simpler solutions. I assume the reason you believe you need a macro is this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;define model display "&amp;amp;location (&amp;amp;var1)";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but there are other ways to achieve this, and without macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, a BY variable can be placed in a title or footnote in such a manner that the title or footnote changes each time the BY variable changes. So you don't need &amp;amp;location as a macro variable to display above each column, it could appear in the title and change appropriately when the BY variable changes. You could do the same with &amp;amp;var1, compute it and then add it into a title or footnoate, and suddenly, no macros are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now this isn't EXACTLY the output you requested with your macro code, but it contains the same information; and thus I repeat my opening point, sometimes there are much simpler approaches if you can avoid specifying that the code MUST contain certain elements.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 12:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748661#M235140</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-17T12:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to NOT manually type all 50 values in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748925#M235274</link>
      <description>&lt;P&gt;that works, but only for the first subgroup. &amp;amp;var1 retained its values to the next subgroup. Did I do something wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is my actual code to. "&amp;amp;trt1"="&amp;amp;var1" in this situation:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	    select (strip(put(count(distinct usubjid), best.))) into :trt1 from adsl_addv1 where TRT01pN=1 group by siteID ;
		 
quit;


%put &amp;amp;trt1 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jun 2021 16:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748925#M235274</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-06-18T16:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to NOT manually type all 50 values in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748997#M235304</link>
      <description>&lt;P&gt;Can you post the rest of your code so we can see?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 21:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p/748997#M235304</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-18T21:26:26Z</dc:date>
    </item>
  </channel>
</rss>

