<?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: Repetitively executing a Maco in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441528#M110482</link>
    <description>&lt;P&gt;I think the issue that keeps popping up is that this dataset is sorted in the following way&lt;BR /&gt;&lt;BR /&gt;Asset &amp;gt; Mapping &amp;gt; Performing &amp;gt; Fixed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So your code is just returning one column and just the word segment, which is strange but there are more constraints in play than just the segment part&lt;/P&gt;</description>
    <pubDate>Fri, 02 Mar 2018 10:16:10 GMT</pubDate>
    <dc:creator>89974114</dc:creator>
    <dc:date>2018-03-02T10:16:10Z</dc:date>
    <item>
      <title>Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441508#M110467</link>
      <description>&lt;P&gt;I am working with a dataset that in reality will have thousands of segments. For illustration I have enclosed 8.&lt;/P&gt;&lt;P&gt;What I am looking to do is to create a dataset for each segment so I can calculate the contribution of each dataset. I have done the majority of the work but what I am asking is to take every row of this output and turn it into its own dataset.&lt;/P&gt;&lt;P&gt;The data set looks like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID    Segment    Asset    Mapping    Performing    Fixed 

1     Loan       Asset    Loan1      Performing    Fixed
2     Loan       Asset    Loan1      No            Fixed
3     Loan       Asset    Loan1      P             Floating
4     Loan       Asset    Loan1      N             floating
5     Loan       Asset    Loan2      P             Fixed
...
8     Loan       Asset    Loan2      N             Floating&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The Data is already nicely sorted as above.&lt;/P&gt;&lt;P&gt;The Macro I have written is as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%macro BinData(i);

Data Bin&amp;amp;i;
set Import;
If _N_ = &amp;amp;i ;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there such a way to repetitively loop this macro for the (in the larger picture) all 8 (1000) segments, something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc
do x=1 to 8;
%bindata(x);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The importance is focused on creating a separate dataset for every segment.&amp;nbsp;TIA.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441508#M110467</guid>
      <dc:creator>89974114</dc:creator>
      <dc:date>2018-03-02T09:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441514#M110471</link>
      <description>&lt;P&gt;Don't split datasets, use by-group processing instead. I guess you wanted to use each single segment to extract data from another dataset?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441514#M110471</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-02T09:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441517#M110473</link>
      <description>&lt;P&gt;This will server the Purpose.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID:best12.    Segment:$10.    Asset:$10.    Mapping:$10.    Performing:$10.    Fixed:$10.;
datalines;
1     Loan       Asset    Loan1      Performing    Fixed
2     Loan       Asset    Loan1      No            Fixed
3     Loan       Asset    Loan1      P             Floating
4     Loan       Asset    Loan2      N             floating
5     Card       Asset    Card1      P             Fixed
8     Card       Asset    Card2      N             Floating
;
run;

proc sql;
create table list as
select distinct Segment as Segment from have;
quit;
%let cnt=&amp;amp;sqlobs;
%put &amp;amp;cnt;

%macro do_it;

%do i=1 %to &amp;amp;cnt;
	proc sql;
	select Segment into :Segment from list(firstobs = &amp;amp;i obs = &amp;amp;i);
	quit;
	
	data &amp;amp;Segment.;
	set have;
	where Segment="&amp;amp;Segment.";
	run;	
%end;

%mend;

%do_it;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441517#M110473</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-02T09:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441520#M110474</link>
      <description>&lt;P&gt;I will be performing a very large macro on each segment to calculate a variety of outputs for every segment, then at the end I'll be creating a cumulative sum of all the segment outputs for each Asset and Liability then subtract the two from each other to get a final projection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So really I need every individual segment to be saved as a datafile to then perform a bunch of operations on each one.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441520#M110474</guid>
      <dc:creator>89974114</dc:creator>
      <dc:date>2018-03-02T09:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441522#M110476</link>
      <description>&lt;P&gt;Still no need to split the dataset. See a simple example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro show_a_person(dataset,index);
proc print data=&amp;amp;dataset (firstobs=&amp;amp;index obs=&amp;amp;index) noobs;
run;
%mend;

data _null_;
set sashelp.class;
call execute('%show_a_person(sashelp.class,'!!put(_n_,best.)!!');');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441522#M110476</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-02T09:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441525#M110479</link>
      <description>&lt;P&gt;I'm getting some errors with this code. It just returns the Segments and not the resulting columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In an ideal world I'd like to just save every row in the order it have been sorted as individual datasets in the work lib.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 10:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441525#M110479</guid>
      <dc:creator>89974114</dc:creator>
      <dc:date>2018-03-02T10:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441526#M110480</link>
      <description>&lt;P&gt;This looks lovely on the Proc Print, cheers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although, If I was to continue to take each segment and then put that segment through a vigorous process of extracting the payment schedule, turning it into a maturity profile and so on, Would it be possible to call on each segment to put into my next macro iteratively?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So taking each segment, I'd like to then again loop each segment into another macro which encloses all the procedures I need to apply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Sort the datawarehouse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. separate the segments into individual observations / rows / subsets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. apply each segment to the macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. sum the results of each segment.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 10:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441526#M110480</guid>
      <dc:creator>89974114</dc:creator>
      <dc:date>2018-03-02T10:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441527#M110481</link>
      <description>&lt;P&gt;That is possibly the issue with Variable length and space. I had used strip function. Please find the modified code&lt;/P&gt;&lt;P&gt;&amp;nbsp;And the order wont change in the resulting datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table list as
select distinct Segment as Segment from have;
quit;
%let cnt=&amp;amp;sqlobs;
%put &amp;amp;cnt;

%macro do_it;

%do i=1 %to &amp;amp;cnt;
	proc sql;
	select Segment into :Segment from list(firstobs = &amp;amp;i obs = &amp;amp;i);
	quit;
	
	data &amp;amp;Segment.;
	set have;
	where strip(Segment)=strip("&amp;amp;Segment."); /*Using Strip*/
	run;	
%end;

%mend;

%do_it;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 10:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441527#M110481</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-02T10:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441528#M110482</link>
      <description>&lt;P&gt;I think the issue that keeps popping up is that this dataset is sorted in the following way&lt;BR /&gt;&lt;BR /&gt;Asset &amp;gt; Mapping &amp;gt; Performing &amp;gt; Fixed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So your code is just returning one column and just the word segment, which is strange but there are more constraints in play than just the segment part&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 10:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441528#M110482</guid>
      <dc:creator>89974114</dc:creator>
      <dc:date>2018-03-02T10:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441529#M110483</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196171"&gt;@89974114&lt;/a&gt;&amp;nbsp;This is a very strange requirement. I understood you need data per variable segment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A little modification to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro show_a_person(dataset,index);
data &amp;amp;dataset._&amp;amp;index.;
set &amp;amp;dataset.(firstobs=&amp;amp;index obs=&amp;amp;index);
run;
%mend;

data _null_;
set sashelp.class;
call execute('%show_a_person(sashelp.class,'!!put(_n_,best.)!!');');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There you go. Just replace sashelp.class with your work dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 10:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441529#M110483</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-02T10:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitively executing a Maco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441531#M110484</link>
      <description>&lt;P&gt;This code is a lot better looking than the solution I managed to come out with:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro BinData;

%do i = 1 %to 8;

Data Bin&amp;amp;i;
set Import;
If _N_ = &amp;amp;i;
run;

%end;

%mend;

%bindata();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your code, I'll be using this to complete my project, looks great.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 10:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitively-executing-a-Maco/m-p/441531#M110484</guid>
      <dc:creator>89974114</dc:creator>
      <dc:date>2018-03-02T10:47:50Z</dc:date>
    </item>
  </channel>
</rss>

