<?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: how to output simulated data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503919#M134766</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
Shape = {74, 104, 38, 24};
x = RandDirichlet(n,Shape);
print x;

create MyData var {x};
append;
close MyData;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Oct 2018 21:29:01 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-10-12T21:29:01Z</dc:date>
    <item>
      <title>how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503913#M134763</link>
      <description>&lt;P&gt;I use the following code to simulate some data but do not know how to output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when I use print x it printed only 3 columns data, not 4 columns. Please help.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
Shape = {74, 104, 38, 24};
x = RandDirichlet(n,Shape);
print x;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 21:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503913#M134763</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2018-10-12T21:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503919#M134766</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
Shape = {74, 104, 38, 24};
x = RandDirichlet(n,Shape);
print x;

create MyData var {x};
append;
close MyData;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 21:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503919#M134766</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-12T21:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503920#M134767</link>
      <description>&lt;P&gt;yes, but this only output one column of data with 3000 rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to output a data set with 1000 rows and 4 columns&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 21:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503920#M134767</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2018-10-12T21:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503932#M134771</link>
      <description>&lt;P&gt;You have to list the columns but otherwise the process is the same.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this blog post:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56807"&gt;@fengyuwuzu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;yes, but this only output one column of data with 3000 rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to output a data set with 1000 rows and 4 columns&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 22:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503932#M134771</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-12T22:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503984#M134799</link>
      <description>&lt;P&gt;Why do you expect this to be 4 columns and not one? Just trying to figure out what you want to do.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 05:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503984#M134799</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-13T05:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503986#M134801</link>
      <description>&lt;P&gt;Sorry, I&amp;nbsp;did not make it clear in my original post.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data has 4 categories, so each category has a percentage, and the 4 percentages add up to 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I want to simulate a random sample of these 4 percentages, using randdirichlet,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want to get random sample data set,&amp;nbsp;which will have&amp;nbsp;1000 rows of 4 columns, each column is the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;percentage of&amp;nbsp;one category.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I did not specify the shape correctly, so I only got 3 columns of percentages when I print it?&lt;/P&gt;
&lt;P&gt;I have total (74+104+38+24) obs, and each number represents the count of one category.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Shape &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;74&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;104&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;38&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;24&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I figured out how to get the 4th percentage, but I am not sure if this is the right way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
Shape = {50, 100, 150, 200};				/* use simple numbers for testing */
x = RandDirichlet(n,Shape);  				/* x is a 1000 x 3 matrix, not 1000 x 4 */
samplemean=mean(x);  					/* check mean */
print samplemean;

varnames='percentage1':'percentage3';
create MyData from x[colname=varnames]; 		/* mydata has only first 3 percentages columns */
append from x;
close MyData;
quit;

data mydata2;
set mydata;
percentage4=1-(percentage1+percentage2+percentage3); /* to get the 4th percentage */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Oct 2018 13:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/503986#M134801</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2018-10-13T13:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to output simulated data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/504041#M134832</link>
      <description>&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;P&gt;The RANDDIRICHLET function generates a random sample from a Dirichlet distribution, which is a multivariate generalization of the beta distribution.&lt;/P&gt;
&lt;P&gt;The input parameters are as follows:&lt;/P&gt;
&lt;DIV class="variablelist deflist"&gt;
&lt;DL class="variablelist deflist"&gt;
&lt;DT&gt;&lt;SPAN class="term"&gt;&lt;SPAN class="phrase argument"&gt;N&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;is the number of observations to sample.&lt;/P&gt;
&lt;/DD&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;SPAN class="term"&gt;&lt;SPAN class="phrase argument"&gt;Shape&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;&lt;STRONG&gt;is a &lt;/STRONG&gt;&lt;SPAN class="inlinemediaobject"&gt;&lt;IMG src="https://support.sas.com/documentation/cdl/en/imlug/65547/HTML/default/images/imlug_modlib0036.png" border="0" alt="$1 \times (p+1)$" width="64" height="16" /&gt;&lt;/SPAN&gt;&lt;STRONG&gt; vector of shape parameters for the distribution, &lt;SPAN class="inlinemediaobject"&gt;&lt;IMG style="margin: 0px; padding: 0px; border: 0px; font-weight: normal; font-style: normal; line-height: 1.25em; font-family: inherit; text-align: left; vertical-align: -4px;" src="https://support.sas.com/documentation/cdl/en/imlug/65547/HTML/default/images/imlug_modlib0037.png" border="0" alt="$\mbox{Shape}[i]&amp;gt;0$" width="74" height="16" /&gt;&lt;/SPAN&gt;.&lt;/STRONG&gt;&lt;/P&gt;
&lt;/DD&gt;
&lt;/DL&gt;
&lt;/DIV&gt;
&lt;P&gt;The RANDDIRICHLET function returns an &lt;SPAN class="inlinemediaobject"&gt;&lt;IMG src="https://support.sas.com/documentation/cdl/en/imlug/65547/HTML/default/images/imlug_modlib0038.png" border="0" alt="$N \times p$" width="35" height="13" /&gt;&lt;/SPAN&gt; matrix that contains &lt;SPAN class="inlinemediaobject"&gt;&lt;IMG src="https://support.sas.com/documentation/cdl/en/imlug/65547/HTML/default/images/imlug_modlib0039.png" border="0" alt="$N$" width="12" height="10" /&gt;&lt;/SPAN&gt; random draws from the Dirichlet distribution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that Shape is supposed to be &lt;STRONG&gt;p+1 vector&lt;/STRONG&gt;, while it returns a &lt;STRONG&gt;N x p&lt;/STRONG&gt; matrix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56807"&gt;@fengyuwuzu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry, I&amp;nbsp;did not make it clear in my original post.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data has 4 categories, so each category has a percentage, and the 4 percentages add up to 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I want to simulate a random sample of these 4 percentages, using randdirichlet,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want to get random sample data set,&amp;nbsp;which will have&amp;nbsp;1000 rows of 4 columns, each column is the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;percentage of&amp;nbsp;one category.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I did not specify the shape correctly, so I only got 3 columns of percentages when I print it?&lt;/P&gt;
&lt;P&gt;I have total (74+104+38+24) obs, and each number represents the count of one category.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Shape &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;74&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;104&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;38&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;24&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I figured out how to get the 4th percentage, but I am not sure if this is the right way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
Shape = {50, 100, 150, 200};				/* use simple numbers for testing */
x = RandDirichlet(n,Shape);  				/* x is a 1000 x 3 matrix, not 1000 x 4 */
samplemean=mean(x);  					/* check mean */
print samplemean;

varnames='percentage1':'percentage3';
create MyData from x[colname=varnames]; 		/* mydata has only first 3 percentages columns */
append from x;
close MyData;
quit;

data mydata2;
set mydata;
percentage4=1-(percentage1+percentage2+percentage3); /* to get the 4th percentage */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/imlug/65547/HTML/default/viewer.htm#imlug_modlib_sect019.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/imlug/65547/HTML/default/viewer.htm#imlug_modlib_sect019.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 20:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-simulated-data-set/m-p/504041#M134832</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-13T20:25:54Z</dc:date>
    </item>
  </channel>
</rss>

