<?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: Runing a do loop with discrete values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65260#M14166</link>
    <description>Suggest you explore executing the code by adding the statement below which will reveal the processing logic/flow:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT;&lt;BR /&gt;
&lt;BR /&gt;
And consider adding MLOGIC as well.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Wed, 18 Aug 2010 16:36:31 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-08-18T16:36:31Z</dc:date>
    <item>
      <title>Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65257#M14163</link>
      <description>I'm trying to run a macro that looks at data at different time periods. Currently I have it looking at time periods on a continuous loop, i.e. from 1 month to 12 months. I want to be able to look at a set of specific time periods instead of a continuous list. &lt;BR /&gt;
&lt;BR /&gt;
For example, I'd like to look at time periods 1,3,6,9,12,18,24 instead of having to run it from 1 to 24.&lt;BR /&gt;
&lt;BR /&gt;
I'll post my code below and point out where I need it to be changed.&lt;BR /&gt;
&lt;BR /&gt;
I know that I can do this outside of the macro language, but for the purposes of naming my data sets and identifying them later on for more analysis I believe I have to do this in a macro setting. Any help at all would be appreciated.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro dosql;&lt;BR /&gt;
&lt;BR /&gt;
%do j = 0 %to 11;&lt;BR /&gt;
		%do i = 1 %to 24;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table time_&amp;amp;j. as&lt;BR /&gt;
select&lt;BR /&gt;
case_nbr,&lt;BR /&gt;
sqnc_nbr,&lt;BR /&gt;
dflt_sts_cd,&lt;BR /&gt;
ft_in_eps_3mnth_delq_dt,&lt;BR /&gt;
dflt_cyc_dt&lt;BR /&gt;
from sf.sfdw_default_history&lt;BR /&gt;
where ft_in_eps_3mnth_delq_dt &amp;lt;= intnx('month',"15&amp;amp;m.&amp;amp;yr."d,&amp;amp;j.,'end')&lt;BR /&gt;
and ft_in_eps_3mnth_delq_dt &amp;gt;= intnx('month',"15&amp;amp;m.&amp;amp;yr."d,&amp;amp;j., 'beginning')&lt;BR /&gt;
order by case_nbr, sqnc_nbr;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data time_&amp;amp;j.;&lt;BR /&gt;
set time_&amp;amp;j.;&lt;BR /&gt;
format status $12. time.2;&lt;BR /&gt;
status = '.';&lt;BR /&gt;
time = '.';&lt;BR /&gt;
run; quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table time_&amp;amp;j._&amp;amp;i. as&lt;BR /&gt;
select  *&lt;BR /&gt;
from time_&amp;amp;j.&lt;BR /&gt;
where dflt_cyc_dt &amp;lt;= intnx('month',ft_in_eps_3mnth_delq_dt,&amp;amp;i., 'end')&lt;BR /&gt;
order by case_nbr, sqnc_nbr;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
set time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
by case_nbr;&lt;BR /&gt;
if (last.case_nbr = 0) then delete;&lt;BR /&gt;
run; quit;&lt;BR /&gt;
&lt;BR /&gt;
data time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
set time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
time = "&amp;amp;i.";&lt;BR /&gt;
eval_time = intnx('month',ft_in_eps_3mnth_delq_dt,&amp;amp;i., 'end');&lt;BR /&gt;
format eval_time date9.;&lt;BR /&gt;
run; quit;&lt;BR /&gt;
&lt;BR /&gt;
data time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
set time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
by eval_time;&lt;BR /&gt;
if eval_time &amp;gt; "&amp;amp;cutoff."d then delete;&lt;BR /&gt;
run; quit;&lt;BR /&gt;
&lt;BR /&gt;
data master_data;&lt;BR /&gt;
set time_0 time_&amp;amp;j._&amp;amp;i.;&lt;BR /&gt;
run; quit;&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
options mprint;&lt;BR /&gt;
%dosql;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
So where it has i = 1 %to 24&lt;BR /&gt;
I want to run it over a discrete list of numbers rather than all 24&lt;BR /&gt;
&lt;BR /&gt;
Thanks again,&lt;BR /&gt;
&lt;BR /&gt;
Kris G</description>
      <pubDate>Wed, 18 Aug 2010 15:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65257#M14163</guid>
      <dc:creator>KrisG</dc:creator>
      <dc:date>2010-08-18T15:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65258#M14164</link>
      <description>This piece of code might give you an idea&lt;BR /&gt;
[pre]&lt;BR /&gt;
 %macro doit(b=) ;               &lt;BR /&gt;
   %let i = 1 ;                  &lt;BR /&gt;
   %do %until(%scan(&amp;amp;b,&amp;amp;i) eq) ; &lt;BR /&gt;
      %put &amp;amp;i %scan(&amp;amp;b,&amp;amp;i) ;     &lt;BR /&gt;
      %let i = %eval(&amp;amp;i+1) ;     &lt;BR /&gt;
   %end ;                        &lt;BR /&gt;
 %mend ;                 &lt;BR /&gt;
&lt;BR /&gt;
 %let a = 1 3 6 9 12 18 24 ;     &lt;BR /&gt;
&lt;BR /&gt;
 %doit(b=&amp;amp;a) ;                   &lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 18 Aug 2010 16:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65258#M14164</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-08-18T16:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65259#M14165</link>
      <description>If i use that code provided, do i leave the references to "i" still when naming the datasets? &lt;BR /&gt;
&lt;BR /&gt;
for example, where I name a set time_&amp;amp;j._&amp;amp;i.  &lt;BR /&gt;
&lt;BR /&gt;
Or where I have &amp;amp;i. listed, is there something else I have put there instead in order to have the files take on those discrete values.</description>
      <pubDate>Wed, 18 Aug 2010 16:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65259#M14165</guid>
      <dc:creator>KrisG</dc:creator>
      <dc:date>2010-08-18T16:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65260#M14166</link>
      <description>Suggest you explore executing the code by adding the statement below which will reveal the processing logic/flow:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT;&lt;BR /&gt;
&lt;BR /&gt;
And consider adding MLOGIC as well.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 18 Aug 2010 16:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65260#M14166</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-18T16:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65261#M14167</link>
      <description>My code sample lacked a bit of clearness obviously.&lt;BR /&gt;
In order to use the discrete values replace&lt;BR /&gt;
&lt;BR /&gt;
  %put  &amp;amp;i %scan(&amp;amp;b,&amp;amp;i) ;&lt;BR /&gt;
&lt;BR /&gt;
by e.g.&lt;BR /&gt;
&lt;BR /&gt;
  %let disc_i = %scan(&amp;amp;b,&amp;amp;i) ;&lt;BR /&gt;
&lt;BR /&gt;
and use  &amp;amp;disc_i  in place of your &amp;amp;i.&lt;BR /&gt;
&lt;BR /&gt;
Apply similar logic for your &amp;amp;j variable.&lt;BR /&gt;
&lt;BR /&gt;
Hope this clears the mud a bit.&lt;BR /&gt;
Robert</description>
      <pubDate>Wed, 18 Aug 2010 17:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65261#M14167</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-08-18T17:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65262#M14168</link>
      <description>Thank you for the help, i was able to make it work with your code.&lt;BR /&gt;
&lt;BR /&gt;
Kris G</description>
      <pubDate>Wed, 18 Aug 2010 20:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65262#M14168</guid>
      <dc:creator>KrisG</dc:creator>
      <dc:date>2010-08-18T20:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65263#M14169</link>
      <description>in open code data step, this will work also:&lt;BR /&gt;
data test;&lt;BR /&gt;
do i= 1, 3, 4,  28;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 25 Aug 2010 19:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65263#M14169</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-08-25T19:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Runing a do loop with discrete values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65264#M14170</link>
      <description>you could use %if &amp;amp;i=1 or &amp;amp;i=3 or &amp;amp;i=6 %then %do;</description>
      <pubDate>Thu, 26 Aug 2010 13:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Runing-a-do-loop-with-discrete-values/m-p/65264#M14170</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2010-08-26T13:31:01Z</dc:date>
    </item>
  </channel>
</rss>

