<?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: loops in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581949#M165452</link>
    <description>&lt;P&gt;Maxim 1: Read the Documentation. For functions, go here:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Aug 2019 18:41:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-08-17T18:41:47Z</dc:date>
    <item>
      <title>Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581934#M165439</link>
      <description>&lt;P&gt;Hi everyone, I have a question about loop. Here I have a sample data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
input stkcd $ ViolationYear $30.;
datalines;
000003 2001
000004 2008,2009,2010
000007 2011,2012,2013,2014
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to split the year in ViolationYear and rearrange to be like one stkcd match one ViolationYear liike:&lt;/P&gt;
&lt;P&gt;000003 2001&lt;/P&gt;
&lt;P&gt;000004 2008&lt;/P&gt;
&lt;P&gt;000004 2009&lt;/P&gt;
&lt;P&gt;000004 2010&lt;/P&gt;
&lt;P&gt;000007 2011&lt;/P&gt;
&lt;P&gt;000007 2012&lt;/P&gt;
&lt;P&gt;and so on.&lt;/P&gt;
&lt;P&gt;I am wondering if I can use a loop to achieve this or is there any other better choice? Looking forward to your suggestions.&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 16:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581934#M165439</guid>
      <dc:creator>Eco</dc:creator>
      <dc:date>2019-08-17T16:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: loops in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581935#M165440</link>
      <description>&lt;P&gt;There is no need for MACRO code for this problem.&amp;nbsp; You don't need to generate code statements.&amp;nbsp; Just write normal SAS code to generate the observations you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  input stkcd :$10. ViolationYear :$30.;
datalines;
000003 2001
000004 2008,2009,2010
000007 2011,2012,2013,2014
;

data want ;
  set sample;
  do sample_no=1 by 1 until (sample_no=countw(ViolationYear,','));
     Year = input(scan(ViolationYear,sample_no,','),32.);
     output;
  end;
  drop ViolationYear;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                 sample_
Obs    stkcd        no      Year

 1     000003       1       2001
 2     000004       1       2008
 3     000004       2       2009
 4     000004       3       2010
 5     000007       1       2011
 6     000007       2       2012
 7     000007       3       2013
 8     000007       4       2014&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 16:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581935#M165440</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-17T16:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581936#M165441</link>
      <description>&lt;P&gt;Nothing to do with macro (that's why I changed the subject line).&lt;/P&gt;
&lt;P&gt;But it's done with a data step do loop and some string functions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sample;
do i = 1 to countw(violationyear,',');
  year = input(scan(violationyear,i,',');
  output;
end;
drop i violationyear;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196117"&gt;@Eco&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone, I have a question about loop. Here I have a sample data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
input stkcd $ ViolationYear $30.;
datalines;
000003 2001
000004 2008,2009,2010
000007 2011,2012,2013,2014
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to split the year in ViolationYear and rearrange to be like one stkcd match one ViolationYear liike:&lt;/P&gt;
&lt;P&gt;000003 2001&lt;/P&gt;
&lt;P&gt;000004 2008&lt;/P&gt;
&lt;P&gt;000004 2009&lt;/P&gt;
&lt;P&gt;000004 2010&lt;/P&gt;
&lt;P&gt;000007 2011&lt;/P&gt;
&lt;P&gt;000007 2012&lt;/P&gt;
&lt;P&gt;and so on.&lt;/P&gt;
&lt;P&gt;I am wondering if I can use a loop to achieve this or is there any other better choice? Looking forward to your suggestions.&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 16:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581936#M165441</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-17T16:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: loops in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581937#M165442</link>
      <description>&lt;P&gt;Thank you very much Tom, it seems I have made the queation complicate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 16:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581937#M165442</guid>
      <dc:creator>Eco</dc:creator>
      <dc:date>2019-08-17T16:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581938#M165443</link>
      <description>&lt;P&gt;Thank you Kurt, it works~ It seems I have made the question complicate.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 16:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581938#M165443</guid>
      <dc:creator>Eco</dc:creator>
      <dc:date>2019-08-17T16:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: loops in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581939#M165444</link>
      <description>&lt;P&gt;By the way, is there any way that I can find such kind of functions or to learn them systematiclly? I think these functions are so tiny that I cannot find them easily...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 16:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581939#M165444</guid>
      <dc:creator>Eco</dc:creator>
      <dc:date>2019-08-17T16:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: loops in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581940#M165445</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196117"&gt;@Eco&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;By the way, is there any way that I can find such kind of functions or to learn them systematiclly? I think these functions are so tiny that I cannot find them easily...&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a very vague question, and yes, there are a gajillion books and tutorials available on SAS that will help you learn, plus comprehensive online documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One helpful book is called "The Little SAS Book". Some others are listed here: &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0w77a6p4lu418n15il3ltm2y1vv.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0w77a6p4lu418n15il3ltm2y1vv.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 17:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581940#M165445</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-17T17:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: loops in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581941#M165446</link>
      <description>&lt;P&gt;Oh yes, The Little SAS Book. I heard about it before but I haven't tried it. The reference books that I used from now are my university's teaching materials which are not enough for now. It seems to be a long journey for me to learn SAS. Thank you for your suggestion~&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 17:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581941#M165446</guid>
      <dc:creator>Eco</dc:creator>
      <dc:date>2019-08-17T17:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: loops in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581949#M165452</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation. For functions, go here:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 18:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/581949#M165452</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-17T18:41:47Z</dc:date>
    </item>
  </channel>
</rss>

