<?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 Can a dataset with c variables and n rows be created from an n x c array? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787561#M40042</link>
    <description>&lt;P&gt;I've unsuccessfully attempted to use nested do loops to output the array observations to an empty dataset with variables x1-x&amp;amp;cols.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let numrows=8;
%let numcols=3;
data work.test_combs_1;
input x1-x&amp;amp;numcols;
datalines;
. . .
;
run;
data work.test_combs_2;
set work.test_combs_1;
  array test_array[&amp;amp;numrows,&amp;amp;numcols] (%eval(&amp;amp;numrows*&amp;amp;numcols)*0);
  do i=1 to &amp;amp;numrows;
    do j=1 to &amp;amp;numcols;
      x&amp;amp;j = (test_array[i,j]);
	  output;
	end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;num&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Dec 2021 23:24:37 GMT</pubDate>
    <dc:creator>RobertWF1</dc:creator>
    <dc:date>2021-12-28T23:24:37Z</dc:date>
    <item>
      <title>Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787561#M40042</link>
      <description>&lt;P&gt;I've unsuccessfully attempted to use nested do loops to output the array observations to an empty dataset with variables x1-x&amp;amp;cols.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let numrows=8;
%let numcols=3;
data work.test_combs_1;
input x1-x&amp;amp;numcols;
datalines;
. . .
;
run;
data work.test_combs_2;
set work.test_combs_1;
  array test_array[&amp;amp;numrows,&amp;amp;numcols] (%eval(&amp;amp;numrows*&amp;amp;numcols)*0);
  do i=1 to &amp;amp;numrows;
    do j=1 to &amp;amp;numcols;
      x&amp;amp;j = (test_array[i,j]);
	  output;
	end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;num&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Dec 2021 23:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787561#M40042</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2021-12-28T23:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787572#M40045</link>
      <description>&lt;P&gt;You need another array.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array test_array[&amp;amp;numrows,&amp;amp;numcols] (%eval(&amp;amp;numrows*&amp;amp;numcols)*0);
  array x [&amp;amp;numcols] ;
  do i=1 to &amp;amp;numrows;
    do j=1 to &amp;amp;numcols;
      x[j] = test_array[i,j];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro variables are not dataset variables.&amp;nbsp; Also remember that the macro processor finishes modifying the code BEFORE the SAS compiler tries to interpret it. And so definitely BEFORE that data step can run.&amp;nbsp; To see what code you are trying to run replace the macro variable references with example values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what are you trying to do?&amp;nbsp; &amp;nbsp;You are replicating every observation read from TEST_COMB_1 by a factoer of &amp;amp;num_rows times &amp;amp;num_cols.&amp;nbsp; And you are setting all of the X variables to zeros because that is all you put into the array.&amp;nbsp; Unless there are variables named TEST_ARRAY1,2,..... that you are reading from TEST_COMB_1.&amp;nbsp; In which case why bother to set initial values when you define the array?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 01:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787572#M40045</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-29T01:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787575#M40046</link>
      <description>Thanks Tom! &lt;BR /&gt;Really all I need to do is write the observations in an r x c array into a dataset having the same dimensions, with r rows and c variables x1, x2, ...</description>
      <pubDate>Wed, 29 Dec 2021 03:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787575#M40046</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2021-12-29T03:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787578#M40047</link>
      <description>&lt;P&gt;You need to move the OUTPUT statement outside of the inner DO loop.&lt;/P&gt;
&lt;P&gt;Move the values from the variables referenced by the multi-dimensional array to the variables referenced by the single dimension array and THEN write the values to the output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An ARRAY is a data step construct to allow you to reference one of a series of variables via an index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you getting data into the ARRAY that you defined?&amp;nbsp; Perhaps there is more to your program than you are showing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So ignoring the issue of how you are going to get the data into your multi-dimensional array (AKA a matrix) here is how you could write that data out to a dataset.&lt;/P&gt;
&lt;P&gt;So if you have 6 observations and 5 variables (AKA 6 rows and 5 columns) the code would look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   array matrix [6,5] ;
   array vars [5] age ht wt sysbp diabp;
* do something to populate the MATRIX array ;
* where is the data coming from? ;
* Write the matrix array to a dataset ;
  do obs=1 to 6;
    do col=1 to 5;
      vars[col] = matrix[obs,col];
    end;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Dec 2021 03:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787578#M40047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-29T03:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787583#M40049</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/408179"&gt;@RobertWF1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've unsuccessfully attempted to use nested do loops to output the array observations to an empty dataset with variables x1-x&amp;amp;cols.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why? The usage of arrays in sas differs in many ways from their usage in other programming languages: it is just a shortcut to access multiple variables defined in one observation, all having the same type. It seems as if you are trying to transpose a dataset, or am i on the wrong track?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 06:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787583#M40049</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-12-29T06:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787629#M40052</link>
      <description>I'm working on a project at work where I have to calculate the expected value of an average treatment effect (ATE) for an outcome (like total medical cost) for a simulated dataset using a data generating process ( a regression). &lt;BR /&gt;&lt;BR /&gt;This involves calculating the expected value across all combinations of k dummy variables. SAS doesn't have a procedure or function that performs this, but Rick Wicklin posted a how-to article (&lt;A href="https://blogs.sas.com/content/iml/2011/01/05/creating-a-matrix-with-all-combinations-of-zeros-and-ones.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2011/01/05/creating-a-matrix-with-all-combinations-of-zeros-and-ones.html&lt;/A&gt;) which discusses using the binary format option to recast numbers as their binary equivalent, the end result being an output matrix containing all 2^k combinations of 1s and 0s.&lt;BR /&gt;&lt;BR /&gt;However my employer hasn't purchased the IML module so I've had to use *arrays* rather than matrices (and plenty help here in the SAS forum!). &lt;BR /&gt;&lt;BR /&gt;I can generate the array of 1s and 0s now, but in order to find the expected ATE I have to convert the array into a dataset.</description>
      <pubDate>Wed, 29 Dec 2021 15:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787629#M40052</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2021-12-29T15:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787649#M40053</link>
      <description>Ah, I just read the comments at the bottom of Rick Wicklin's post - and see that someone posted a simple macro for creating a dataset with all combinations of 1s and 0s, using a Cartesian product in proc sql. Very handy &amp;amp; simple to use, although not quite sure I understand what his code is doing here:&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select memname into:d separated by ','&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where upcase(libname)="WORK" and upcase(substr(memname,1,3))="__D"&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Dec 2021 17:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787649#M40053</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2021-12-29T17:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787661#M40054</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/408179"&gt;@RobertWF1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Ah, I just read the comments at the bottom of Rick Wicklin's post - and see that someone posted a simple macro for creating a dataset with all combinations of 1s and 0s, using a Cartesian product in proc sql. Very handy &amp;amp; simple to use, although not quite sure I understand what his code is doing here:&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select memname into:d separated by ','&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where upcase(libname)="WORK" and upcase(substr(memname,1,3))="__D"&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That step is making a macro variable, &amp;amp;D, that contains a space delimited list of all of the work datasets whose name starts with two underscores and the letter D.&amp;nbsp; Presumably to be used later in a SET or other statement where you could reference a list of datasets.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 17:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787661#M40054</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-29T17:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can a dataset with c variables and n rows be created from an n x c array?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787662#M40055</link>
      <description>&lt;P&gt;A dataset is essentially a matrix with NOBS == NROWS and NVARS == NCOLS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a data step to multiply two such matrices (with a little work).&amp;nbsp; I did that 25-30 years ago to deal with matrices my wife needed to multiply that were too large to load into memory to use IML (or PROC MATRIX back then).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use PROC SCORE to multiply matrices.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 17:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-a-dataset-with-c-variables-and-n-rows-be-created-from-an-n-x/m-p/787662#M40055</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-29T17:37:33Z</dc:date>
    </item>
  </channel>
</rss>

