<?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 How to make a dynamic macrofor splitting a dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820720#M323982</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Have*/

data insimp2;
	set sashelp.cars(keep=make type origin cylinders horsepower);
run;

proc sql;
	select distinct make into: vak1-
	from work.insimp2;
quit;

%put &amp;amp;sqlobs.;
%put &amp;amp;vak1.;

%MACRO GDATA(nbs,vak);
	proc sql;
		create table work.insimp2_&amp;amp;nbs. as
			select * from work.insimp2
			group by cylinders
				having (Make="&amp;amp;vak.")
				order by origin, horsepower asc;
	quit;
%MEND GDATA; 

/* WANT */

/*
I Want for every make of the car to run the macro. So the macro dynamically creates datasets with 1 make of every car
Obviously I can do it like this: 

%GDATA(1,&amp;amp;vak1.);
%GDATA(2,&amp;amp;vak2.);
etc.
%GDATA(38,&amp;amp;vak38.);


But in this case the dataset must always have 38 obs to keep working. 
But I want this macro to run without knowing that there are 38 makes (like in this case).
So maybe there could be 20 or maybe 200 makes.. 
the macro should run without hardcoding the obs.
How do I do this?  

*/
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks in Advance guys!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2022 17:01:36 GMT</pubDate>
    <dc:creator>SAS_Question</dc:creator>
    <dc:date>2022-06-28T17:01:36Z</dc:date>
    <item>
      <title>How to make a dynamic macrofor splitting a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820720#M323982</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Have*/

data insimp2;
	set sashelp.cars(keep=make type origin cylinders horsepower);
run;

proc sql;
	select distinct make into: vak1-
	from work.insimp2;
quit;

%put &amp;amp;sqlobs.;
%put &amp;amp;vak1.;

%MACRO GDATA(nbs,vak);
	proc sql;
		create table work.insimp2_&amp;amp;nbs. as
			select * from work.insimp2
			group by cylinders
				having (Make="&amp;amp;vak.")
				order by origin, horsepower asc;
	quit;
%MEND GDATA; 

/* WANT */

/*
I Want for every make of the car to run the macro. So the macro dynamically creates datasets with 1 make of every car
Obviously I can do it like this: 

%GDATA(1,&amp;amp;vak1.);
%GDATA(2,&amp;amp;vak2.);
etc.
%GDATA(38,&amp;amp;vak38.);


But in this case the dataset must always have 38 obs to keep working. 
But I want this macro to run without knowing that there are 38 makes (like in this case).
So maybe there could be 20 or maybe 200 makes.. 
the macro should run without hardcoding the obs.
How do I do this?  

*/
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks in Advance guys!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 17:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820720#M323982</guid>
      <dc:creator>SAS_Question</dc:creator>
      <dc:date>2022-06-28T17:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a dynamic macrofor splitting a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820726#M323987</link>
      <description>&lt;P&gt;No need to move the data into macro variables to generate the macro calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the data in a data step instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=insimp2;
  tables make / noprint out=counts;
run;

data _null_;
  set counts;
  call execute(cats('%nrstr(%gdata)(',_n_,make,')'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jun 2022 16:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820726#M323987</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-28T16:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a dynamic macrofor splitting a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820730#M323991</link>
      <description>SWEET! I love your simple solutions &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;! Great! Thanks al lot! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 28 Jun 2022 16:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-dynamic-macrofor-splitting-a-dataset/m-p/820730#M323991</guid>
      <dc:creator>SAS_Question</dc:creator>
      <dc:date>2022-06-28T16:39:58Z</dc:date>
    </item>
  </channel>
</rss>

