<?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: Simulating categorical data, same observations per group. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/894990#M353544</link>
    <description>&lt;P&gt;Not with that code. The Rand function wants a comma between each parameter and you are missing comma for the last table value.&lt;/P&gt;
&lt;P&gt;You also aren't accounting for the occasional 4 that table will give as the sum of .333+.333+.333 = .999 . So you will get some 4 with probability 0.001. I ran a million trials and have 972 4's in the result. Which is where you are getting your missing M, XM, D1M, D2M and Y&amp;nbsp; values from. Was that intentional?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Random" means that unless a process is deterministic (i.e. X=3 all the time) the distributions change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Describe the purpose of forcing "random" group assignments to have the same number.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Sep 2023 23:30:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-09-19T23:30:27Z</dc:date>
    <item>
      <title>Simulating categorical data, same observations per group.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/894989#M353543</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am generating categorical data (X=1, X=2, X=3) with the same probability (.333,.333,.333). I want to ask if there is a way to simulate data for these three groups and ensure that the groups have the same number of observations.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA SIM;&lt;BR /&gt;call streaminit(331980);&lt;BR /&gt;totaln=&amp;amp;NSIM*&amp;amp;NOBS;&lt;BR /&gt;DO I=1 TO totaln;&lt;BR /&gt;X=RAND('Table',.333, .333.333);&lt;BR /&gt;D1=0; D2=0;&lt;BR /&gt;if X=1 THEN DO; D1=0; D2=0; end;&lt;BR /&gt;if X=2 THEN DO; D1=1; D2=0; end;&lt;BR /&gt;if X=3 THEN DO; D1=0; D2=1; end;&lt;BR /&gt;M = &amp;amp;i0m + (&amp;amp;a1*D1)+(&amp;amp;a2*D2)+(&amp;amp;errorm)*RAND('NORMAL');&lt;BR /&gt;XM=x*m;&lt;BR /&gt;D1M=D1*M;&lt;BR /&gt;D2M=D2*M;&lt;BR /&gt;Y= &amp;amp;i0y +(&amp;amp;cp1*D1)+(&amp;amp;cp2*D2)+(&amp;amp;b*M)+(&amp;amp;h1*D1M)+ (&amp;amp;h2*D2M)+(&amp;amp;errory)*RAND('NORMAL');&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2023 22:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/894989#M353543</guid>
      <dc:creator>DianaAlvarezB</dc:creator>
      <dc:date>2023-09-19T22:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating categorical data, same observations per group.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/894990#M353544</link>
      <description>&lt;P&gt;Not with that code. The Rand function wants a comma between each parameter and you are missing comma for the last table value.&lt;/P&gt;
&lt;P&gt;You also aren't accounting for the occasional 4 that table will give as the sum of .333+.333+.333 = .999 . So you will get some 4 with probability 0.001. I ran a million trials and have 972 4's in the result. Which is where you are getting your missing M, XM, D1M, D2M and Y&amp;nbsp; values from. Was that intentional?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Random" means that unless a process is deterministic (i.e. X=3 all the time) the distributions change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Describe the purpose of forcing "random" group assignments to have the same number.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2023 23:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/894990#M353544</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-19T23:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating categorical data, same observations per group.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/895029#M353565</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs=3000;

DATA SIM;
call streaminit(331980);
do n=1 to &amp;amp;nobs.;
 x=rand('normal');output;
end;
run;

proc surveyselect data=sim out=want groups=3 seed=123;
run;

/*verify the result*/
proc freq data=want;
table GroupID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Sep 2023 11:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/895029#M353565</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-09-20T11:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating categorical data, same observations per group.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/895207#M353659</link>
      <description>&lt;P&gt;Sure, specify the number of groups and the number of observations in each, then do the simulation within each group. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let NSIM=10;
%let NGROUPS=3;
%let NOBSPERGROUP=4;

DATA SIM;
call streaminit(331980);
do SampleID = 1 to &amp;amp;NSIM;
   do X = 1 to &amp;amp;NGROUPS;    /* group ID */
      do ObsNum = 1 to &amp;amp;NOBSPERGROUP;
         /* put any computations here */
         D1=0; D2=0;
         if X=1 THEN DO; D1=0; D2=0; end;
         if X=2 THEN DO; D1=1; D2=0; end;
         if X=3 THEN DO; D1=0; D2=1; end;
         M = &amp;amp;i0m + (&amp;amp;a1*D1)+(&amp;amp;a2*D2)+(&amp;amp;errorm)*RAND('NORMAL');
         XM=X*m;
         D1M=D1*M;
         D2M=D2*M;
         Y= &amp;amp;i0y +(&amp;amp;cp1*D1)+(&amp;amp;cp2*D2)+(&amp;amp;b*M)+(&amp;amp;h1*D1M)+ (&amp;amp;h2*D2M)+(&amp;amp;errory)*RAND('NORMAL');
         OUTPUT;
      end;
   end;
end;
run;

proc freq data=sim;
   tables SampleID*X / nocum norow nocol nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Sep 2023 10:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-categorical-data-same-observations-per-group/m-p/895207#M353659</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-09-21T10:31:28Z</dc:date>
    </item>
  </channel>
</rss>

