<?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 Use loop variable to create data set in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Use-loop-variable-to-create-data-set/m-p/35645#M168</link>
    <description>Is it possible to use loop counter to create SAS dataset? For example, in the code below I want to create SAS datasets called test_1, test_2, and test_3.&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
&lt;BR /&gt;
A = {0};&lt;BR /&gt;
&lt;BR /&gt;
do i = 1 to 3;&lt;BR /&gt;
 A = A || i;&lt;BR /&gt;
 print A;&lt;BR /&gt;
 create test_&amp;amp;i from A;&lt;BR /&gt;
 append from A;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
quit;</description>
    <pubDate>Wed, 30 Dec 2009 15:33:40 GMT</pubDate>
    <dc:creator>model_coder</dc:creator>
    <dc:date>2009-12-30T15:33:40Z</dc:date>
    <item>
      <title>Use loop variable to create data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Use-loop-variable-to-create-data-set/m-p/35645#M168</link>
      <description>Is it possible to use loop counter to create SAS dataset? For example, in the code below I want to create SAS datasets called test_1, test_2, and test_3.&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
&lt;BR /&gt;
A = {0};&lt;BR /&gt;
&lt;BR /&gt;
do i = 1 to 3;&lt;BR /&gt;
 A = A || i;&lt;BR /&gt;
 print A;&lt;BR /&gt;
 create test_&amp;amp;i from A;&lt;BR /&gt;
 append from A;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
quit;</description>
      <pubDate>Wed, 30 Dec 2009 15:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Use-loop-variable-to-create-data-set/m-p/35645#M168</guid>
      <dc:creator>model_coder</dc:creator>
      <dc:date>2009-12-30T15:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use loop variable to create data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Use-loop-variable-to-create-data-set/m-p/35646#M169</link>
      <description>The question is: can you define the name of a SAS data set at runtime?&lt;BR /&gt;
I think it will be difficult to use a macro to do this because the names of the data sets aren't known until runtime, whereas the macro language is a preprocessor that substitutes code before the proc is run.&lt;BR /&gt;
&lt;BR /&gt;
Defining the name of a SAS data set at runtime is simple in SAS/IML Studio, since you can use expressions for I/O statements such as the CREATE statement:&lt;BR /&gt;
&lt;BR /&gt;
/* The following example runs in SAS/IML Studio, but not PROC IML */&lt;BR /&gt;
A = {0};&lt;BR /&gt;
do i = 1 to 3;&lt;BR /&gt;
   A = A || i;&lt;BR /&gt;
   DSName = "test_" + strip(char(i));&lt;BR /&gt;
   create (DSName) from A;&lt;BR /&gt;
   append from A;&lt;BR /&gt;
   close (DSName);&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
In PROC IML, you can to use the EXECUTE statement to define the name of the data set at run time:&lt;BR /&gt;
/* Similar idea; runs in PROC IML */&lt;BR /&gt;
proc iml;&lt;BR /&gt;
&lt;BR /&gt;
start WriteMatrix(a, DSName);&lt;BR /&gt;
  CreateStmt = "create " + DSName + " from A;";&lt;BR /&gt;
  CloseStmt = "close " + DSName + ";";&lt;BR /&gt;
  call execute(CreateStmt);&lt;BR /&gt;
  append from A;&lt;BR /&gt;
  call execute(CloseStmt);&lt;BR /&gt;
finish;&lt;BR /&gt;
&lt;BR /&gt;
A = {0};&lt;BR /&gt;
do i = 1 to 3;&lt;BR /&gt;
   A = A || i; &lt;BR /&gt;
   DSName = "test_" + strip(char(i));&lt;BR /&gt;
   run WriteMatrix(A, DSName);&lt;BR /&gt;
end;</description>
      <pubDate>Wed, 30 Dec 2009 21:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Use-loop-variable-to-create-data-set/m-p/35646#M169</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2009-12-30T21:49:46Z</dc:date>
    </item>
  </channel>
</rss>

