<?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: Distributing missing records randomly by Percentage in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604945#M175451</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length department $8;
	do i=1 to 10;
		flag=rand('TABLE',0.5,0.3,0.2);
		if flag=1 then department="IT";
		else if flag=2 then department ="Business";
		else department="HR";
		output;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would use custom formats here instead of DEPARTMENT="Business", &lt;EM&gt;etc&lt;/EM&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2019 11:46:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-11-18T11:46:23Z</dc:date>
    <item>
      <title>Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604832#M175398</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a following sample data set with missing values, for which I want to set certain value by percentage randomly. 50% of the records belong to 'IT' Dept, and 30% belong to 'Business' and remaining 20% belong 'HR' dept. How do i achieve this. Output may vary but overall percentage should match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Department&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Department&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;IT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Business&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;IT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;HR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;IT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;HR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;IT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;IT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;Business&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;Business&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 19:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604832#M175398</guid>
      <dc:creator>sas33</dc:creator>
      <dc:date>2019-11-17T19:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604853#M175409</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one of many possible solutions using only Base SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do ID=1 to 10;
  output;
end;
length Department $8;
Department=' ';
run;

data want;
array _d[10] $8 _temporary_ (5*'IT' 3*'Business' 2*'HR');
if _n_=1 then do;
  _iorc_=31415927; /* random seed */
  call ranperm(_iorc_, of _d[*]);
end;
set have;
Department=_d[_n_];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code could be adapted to a HAVE dataset with variable Department being only partially missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If SAS/STAT is available, there are more options, in particular PROC PLAN or PROC SURVEYSELECT. The latter is demonstrated below with a numeric variable Department whose &lt;EM&gt;formatted&lt;/EM&gt; values are "IT", etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value dept
1='IT'
2='Business'
3='HR'
;
run;

proc surveyselect data=have(keep=id)
groups=(5 3 2)
seed=27182818 out=want;
run;

proc datasets lib=work nolist;
modify want;
rename groupid=Department;
format Department dept.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The GROUPS= option requires SAS 9.4. I would prefer this solution if the group sizes were much larger, e.g., 500, 300, 200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 22:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604853#M175409</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-17T22:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604854#M175410</link>
      <description>&lt;P&gt;The function x=rand('table',...) does exactly what you want.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0rssof65ddoyyn1s3kfdap849lr" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0rssof65ddoyyn1s3kfdap849lr&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 23:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604854#M175410</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-17T23:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604879#M175420</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;One way is to store your department values and the corresponding percentages in a file and then use that file to drive the assignment of the departments randomly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  do ID = 1 to 17 ;                                                                                                                     
    output ;                                                                                                                            
  end ;                                                                                                                                 
run ;                                                                                                                                   
                                                                                                                                        
data department_percent ;                                                                                                               
  input department :$8. percent ;                                                                                                       
  cards ;                                                                                                                               
IT       50                                                                                                                             
Business 30                                                                                                                             
HR       20                                                                                                                             
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want (drop = r percent) ;                                                                                                          
  dcl hash h (ordered:"a") ;                                                                                                            
  h.definekey ("r") ;                                                                                                                   
  h.definedata ("department") ;                                                                                                         
  h.definedone () ;                                                                                                                     
  if 0 then set have nobs = n ;                                                                                                         
  do until (z) ;                                                                                                                        
    set department_percent end = z ;                                                                                                    
    do _n_ = 1 to ceil (divide (n * percent, 100)) ;                                                                                    
      r = ranuni (7) ;                                                                                                                  
      h.add() ;                                                                                                                         
    end ;                                                                                                                               
  end ;                                                                                                                                 
  dcl hiter hi ("h") ;                                                                                                                  
  do while (hi.next() = 0) ;                                                                                                            
    set have ;                                                                                                                          
    output ;                                                                                                                            
  end ;                                                                                                                                 
  stop ;                                                                                                                                
run ; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 05:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604879#M175420</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-18T05:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604892#M175427</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length department $8;
	do i=1 to 10;
		flag=rand('TABLE',0.5,0.3,0.2);
		if flag=1 then department="IT";
		else if flag=2 then department ="Business";
		else department="HR";
		output;
	end;
	drop i;
run;

proc freq data=have order=freq;
	table department;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2019 08:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604892#M175427</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-18T08:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604945#M175451</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length department $8;
	do i=1 to 10;
		flag=rand('TABLE',0.5,0.3,0.2);
		if flag=1 then department="IT";
		else if flag=2 then department ="Business";
		else department="HR";
		output;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would use custom formats here instead of DEPARTMENT="Business", &lt;EM&gt;etc&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 11:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604945#M175451</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-18T11:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604974#M175468</link>
      <description>&lt;P&gt;As Paige said , use rand('table',........);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 array x{3} $ 10 ('IT' 'Business' 'HR');
 call streaminit(1234);
 do id=1 to 10;
  Department=x{rand('table',0.5,0.3)};
  output;
 end;
 drop x1-x3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2019 12:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/604974#M175468</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-18T12:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605002#M175481</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Just to avoid the wrong impression that all solutions presented so far could be used exchangeably:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to decide whether you want to&amp;nbsp;randomly assign 'IT', 'Business' and 'HR' either&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;A)&lt;/STRONG&gt;&amp;nbsp;in &lt;EM&gt;fixed&lt;/EM&gt; proportions (50%:30%:20%)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;B)&lt;/STRONG&gt;&amp;nbsp;in &lt;EM&gt;random&lt;/EM&gt; proportions with &lt;EM&gt;expectations&lt;/EM&gt;&amp;nbsp;50%, 30% and 20%, respectively (&lt;EM&gt;multinomial distribution&lt;/EM&gt; with parameters &lt;EM&gt;n&lt;/EM&gt;, 0.5, 0.3, 0.2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to the &lt;EM&gt;n&lt;/EM&gt; IDs with missing Department.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that applying &lt;STRONG&gt;B&lt;/STRONG&gt; to your example (i.e.&amp;nbsp;&lt;EM&gt;n&lt;/EM&gt;=10) means that there's a probability of 91% (!) that at least two of the three percentages will &lt;EM&gt;not&lt;/EM&gt; match their expectations. In particular, it would be more likely (p=0.136) that at least one of the three departments &lt;EM&gt;does not occur at all&lt;/EM&gt; than to achieve the intended percentages&amp;nbsp;50%, 30% and 20% (p=0.085).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;rand('table',...)&lt;/FONT&gt; approach is ideal for specification &lt;STRONG&gt;B&lt;/STRONG&gt;. (Of course, you could try and repeat this type of random assignment again and again until you're satisfied with the observed percentages.)&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 13:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605002#M175481</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-18T13:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605023#M175492</link>
      <description>&lt;P&gt;Thank you everyone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While most of the solutions seems working as expected, i am leaning towards&amp;nbsp;rand('table',...) function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i am also looking to see other columns in the result data set along with ID and Department. looks like output statement only puts whatever is in the do loop.&amp;nbsp; what change should i make&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 14:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605023#M175492</guid>
      <dc:creator>sas33</dc:creator>
      <dc:date>2019-11-18T14:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605049#M175500</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;While most of the solutions seems working as expected ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, three solutions work according to specification &lt;STRONG&gt;A&lt;/STRONG&gt;&amp;nbsp;and two according to specification &lt;STRONG&gt;B&lt;/STRONG&gt;&amp;nbsp;(see definitions in my previous post).&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;... i am leaning towards&amp;nbsp;rand('table',...) function.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is, specification &lt;STRONG&gt;B&lt;/STRONG&gt;, right?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;i am also looking to see other columns in the result data set along with ID and Department. looks like output statement only puts whatever is in the do loop.&amp;nbsp; what change should i make&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If those "other columns" already exist in dataset HAVE and you use a DATA step with a SET HAVE statement to create dataset WANT, then all columns will be present in dataset WANT by default. Moreover,&amp;nbsp;you won't necessarily need a DO loop nor an OUTPUT statement.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 15:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605049#M175500</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-18T15:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605115#M175537</link>
      <description>&lt;P&gt;Here is the code i am trying to use&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array x{3} $ 10 ('IT' 'Business' 'HR');&lt;BR /&gt;call streaminit(1234);&lt;BR /&gt;Dept=x{rand('table',0.6,0.35)};&lt;BR /&gt;output;&lt;BR /&gt;drop x1-x3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics on;&lt;BR /&gt;proc freq data=want;&lt;BR /&gt;table dept / plots=FreqPlot(scale=percent);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Dept&lt;/TD&gt;&lt;TD&gt;Frequency&lt;/TD&gt;&lt;TD&gt;Percent&lt;/TD&gt;&lt;TD&gt;Cumulative&lt;BR /&gt;Frequency&lt;/TD&gt;&lt;TD&gt;Cumulative&lt;BR /&gt;Percent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Business&lt;/TD&gt;&lt;TD&gt;343&lt;/TD&gt;&lt;TD&gt;33.83&lt;/TD&gt;&lt;TD&gt;343&lt;/TD&gt;&lt;TD&gt;33.83&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HR&lt;/TD&gt;&lt;TD&gt;41&lt;/TD&gt;&lt;TD&gt;4.04&lt;/TD&gt;&lt;TD&gt;384&lt;/TD&gt;&lt;TD&gt;37.87&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IT&lt;/TD&gt;&lt;TD&gt;630&lt;/TD&gt;&lt;TD&gt;62.13&lt;/TD&gt;&lt;TD&gt;1014&lt;/TD&gt;&lt;TD&gt;100.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;i think i wanted to see exact percentages. For example in above case i want to see the distribution as 60%, 35% and 5%, however freq table showing little variance for each dept.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 17:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605115#M175537</guid>
      <dc:creator>sas33</dc:creator>
      <dc:date>2019-11-18T17:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605122#M175540</link>
      <description>&lt;P&gt;Exact percentages cannot be done completely at random, and if the number of total observations is not a multiple of 20, you can't get your exact percentages at all.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 18:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605122#M175540</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-18T18:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Distributing missing records randomly by Percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605146#M175553</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;: Your code is correct for specification &lt;STRONG&gt;B&lt;/STRONG&gt;.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i think i wanted to see exact percentages.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This sounds more like specification &lt;STRONG&gt;A&lt;/STRONG&gt;, hence&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;'s or either of my two solutions.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262176"&gt;@sas33&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For example in above case i want to see the distribution as 60%, 35% and 5%, however freq table showing little variance for each dept.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's what I meant by "&lt;EM&gt;random&lt;/EM&gt; proportions." With &lt;EM&gt;n&lt;/EM&gt;=1014 the closest you can get is, of course, 608x 'IT' (59.96%), 355x 'Business' (35.01%) and 51x 'HR' (5.03%). The probability of exactly attaining these values &lt;EM&gt;with the &lt;FONT face="courier new,courier"&gt;rand('table',...)&lt;/FONT&gt; method&lt;/EM&gt;&amp;nbsp;(i.e. specification &lt;STRONG&gt;B&lt;/STRONG&gt;) is as tiny as 0.0015*, so the observed "little variance" is anything but surprising.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(With &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;'s solution you might occasionally get 60&lt;U&gt;9&lt;/U&gt;x 'IT' due the CEIL function and hence one 'Business' or 'HR' less, depending on the random seed, but his example random seed 7 happens to yield the "optimum" values 608, 355 and 51 for &lt;EM&gt;n&lt;/EM&gt;=1014.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* calculated as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;p=exp(lfact(1014)-lfact(608)-lfact(355)-lfact(51)+608*log(.6)+355*log(.35)+51*log(.05));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2019 18:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distributing-missing-records-randomly-by-Percentage/m-p/605146#M175553</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-18T18:35:27Z</dc:date>
    </item>
  </channel>
</rss>

