<?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: Data steps in do loops - possible? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12700#M1400</link>
    <description>Hi:&lt;BR /&gt;
  I'm not sure what you mean by using a do loop to create the data sets. &lt;BR /&gt;
There are 2 ways to create data set with a DATA step program:&lt;BR /&gt;
1) read "raw" data using INFILE/INPUT to create your output data set&lt;BR /&gt;
2) read an existing SAS dataset using a SET statement (you can also read a DBMS file with the right SAS/Access product) &lt;BR /&gt;
 &lt;BR /&gt;
  If you are reading data with a SET statement and you want to output to differently numbered datasets based on a value, such as YEAR, &lt;BR /&gt;
you don't really need a do loop to accomplish this task:&lt;BR /&gt;
                                     &lt;BR /&gt;
[pre]&lt;BR /&gt;
data sale93 sale94 ;&lt;BR /&gt;
  set sashelp.prdsale;&lt;BR /&gt;
  if year = 1993 then output sale93;&lt;BR /&gt;
  else if year = 1994 then output sale94;&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
proc print data=sale93;&lt;BR /&gt;
  title '1993 Sales';&lt;BR /&gt;
run;&lt;BR /&gt;
         &lt;BR /&gt;
proc print data=sale94;&lt;BR /&gt;
  title '1994 Sales';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                           &lt;BR /&gt;
If, for example, the data had the possibility of 1990-1999, but some years were not in the data and you wanted to programmatically run a data step &lt;BR /&gt;
program for each year, then the way to accomplish that might best be in a macro program. &lt;BR /&gt;
&lt;BR /&gt;
It really depends on what you want to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Mon, 30 Mar 2009 14:43:44 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-03-30T14:43:44Z</dc:date>
    <item>
      <title>Data steps in do loops - possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12698#M1398</link>
      <description>I want to create 10 different data sets using the data step method. The only parameter that would affect the content of the data sets is the year, 1990-1999.&lt;BR /&gt;
&lt;BR /&gt;
Is it possible to use a do loop to create the sets (inside a data step?) or is it necessary to write a macro?&lt;BR /&gt;
&lt;BR /&gt;
I would prefer not using a macro.&lt;BR /&gt;
&lt;BR /&gt;
But data steps inside data steps? And the naming of the different sets?&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Anne</description>
      <pubDate>Mon, 30 Mar 2009 07:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12698#M1398</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-30T07:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Data steps in do loops - possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12699#M1399</link>
      <description>Yes you can, using a single DATA step, however you must list each of the 10 SAS data sets on the DATA statement for the SAS DATA step.  &lt;BR /&gt;
&lt;BR /&gt;
Explore SAS documentation and using the MDY function (within the DATA step) to assign a SAS DATE (numeric type) variable in the DO loop, incrementing the year-portion of your SAS variable via the MDY function.  Apply a SAS FORMAT statement to your SAS variable.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 30 Mar 2009 09:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12699#M1399</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-30T09:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data steps in do loops - possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12700#M1400</link>
      <description>Hi:&lt;BR /&gt;
  I'm not sure what you mean by using a do loop to create the data sets. &lt;BR /&gt;
There are 2 ways to create data set with a DATA step program:&lt;BR /&gt;
1) read "raw" data using INFILE/INPUT to create your output data set&lt;BR /&gt;
2) read an existing SAS dataset using a SET statement (you can also read a DBMS file with the right SAS/Access product) &lt;BR /&gt;
 &lt;BR /&gt;
  If you are reading data with a SET statement and you want to output to differently numbered datasets based on a value, such as YEAR, &lt;BR /&gt;
you don't really need a do loop to accomplish this task:&lt;BR /&gt;
                                     &lt;BR /&gt;
[pre]&lt;BR /&gt;
data sale93 sale94 ;&lt;BR /&gt;
  set sashelp.prdsale;&lt;BR /&gt;
  if year = 1993 then output sale93;&lt;BR /&gt;
  else if year = 1994 then output sale94;&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
proc print data=sale93;&lt;BR /&gt;
  title '1993 Sales';&lt;BR /&gt;
run;&lt;BR /&gt;
         &lt;BR /&gt;
proc print data=sale94;&lt;BR /&gt;
  title '1994 Sales';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                           &lt;BR /&gt;
If, for example, the data had the possibility of 1990-1999, but some years were not in the data and you wanted to programmatically run a data step &lt;BR /&gt;
program for each year, then the way to accomplish that might best be in a macro program. &lt;BR /&gt;
&lt;BR /&gt;
It really depends on what you want to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 30 Mar 2009 14:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-steps-in-do-loops-possible/m-p/12700#M1400</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-03-30T14:43:44Z</dc:date>
    </item>
  </channel>
</rss>

