<?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: Drawing a random sample from arbitrary distributions when the probabilities vary among responden in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620091#M182157</link>
    <description>&lt;P&gt;Wonderful FreelanceReinhard! &amp;nbsp;I have used Option1 in the R language and am avoiding it in SAS because the situation does not allow a formula to be built; but even before trying out your Option 2 I am fascinated with the idea. So I am going to "dig in &amp;nbsp;here" and if I get stuck some place I will ask for more help. In any event, at the end to the road, doing all this inside SAS is a huge development since in my simulation work I often am at a point where the micro data file has several variables with simulated values here and there and it is embedded in a SAS dataset.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Jan 2020 21:00:05 GMT</pubDate>
    <dc:creator>LeStatisticien</dc:creator>
    <dc:date>2020-01-26T21:00:05Z</dc:date>
    <item>
      <title>Drawing a random sample from arbitrary distributions when the probabilities vary among respondents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620042#M182126</link>
      <description>&lt;P&gt;Help please. I wish to do a simulation using an arbitrary distribution over the possible values of a categorical variable. The TABLE&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;facility along with RAND&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;seem just&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;what I need; but&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;I have a collection of such distributions.&amp;nbsp;The&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;program must decide which is the correct distribution in this collection to use, based upon the respondent's attributes on a few variables.&lt;BR /&gt;&lt;BR /&gt;I have dug hard in our SAS help literature but I have not found an example&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;where the p(*) can change from one respondent to the next.&amp;nbsp;I would be overjoyed to learn what steps would achieve my goal.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;PS. The way that I have done this outside of SAS is to attach a signature (a list of indicator values) to each distribution (the collection resides in an external data file). My program then computes the signature from a respondent's record, and when this signature matches that of one of the collection of&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;distributions the program will use that distribution to proceed with the simulation. Now I want to stop doing this work outside of SAS.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 03:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620042#M182126</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-26T03:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620062#M182137</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/306617"&gt;@LeStatisticien&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you have a dataset with respondent IDs and several variables, say x1, x2, x3 for example, which determine the distribution to draw a random sample from. The distribution is one of a categorical variable with, say 4 values (1, 2, 3, 4) and hence determined by the probabilities p1, p2, p3 for the first three values (then p4=1-p1-p2-p3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
input id x1-x3;
cards;
1 3 1 4
2 5 9 2
3 8 0 3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 1:&lt;/U&gt; Compute the probabilities from x1, x2, x3 if you know a formula. (I use arbitrary formulas below, just for demonstration.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=100; /* sample size per ID */

data want;
call streaminit(27182818);
set have;
/* compute (arbitrary) probabilities */
p1=1/(3+min(of x:));
p2=1/(3+max(of x:));
p3=1/(3+mean(of x:));
/* draw random samples of size n */
do sampno=1 to &amp;amp;n;
  y=rand('table', of p1-p3);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 2:&lt;/U&gt; Predetermine the probabilities for each "signature" and store them in a SAS dataset. Retrieve them by means of a hash object. (I compute an arbitrary signature below.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data distr;
input sig p1 p2 p3;
cards;
144      .1 .2 .5
15000    .3 .4 .2
32000    .4 .2 .3
43740    .6 .1 .1
48600    .2 .1 .3
15746400 .2 .3 .2
;

%let n=100; /* sample size per ID */

data want(keep=id sampno y);
call streaminit(27182818);
if _n_=1 then do;
  /* load distribution for each signature into hash table */
  dcl hash h(dataset:'distr');
  h.definekey('sig');
  h.definedata('p1','p2','p3');
  h.definedone();
  if 0 then set distr;
end;
set have;
/* compute signature */
sig=2**x1*3**x2*5**x3;
/* retrieve probabilities and draw random samples */
if h.find()=0 then do sampno=1 to &amp;amp;n;
  y=rand('table', of p1-p3);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dataset &lt;FONT face="courier new,courier"&gt;distr&lt;/FONT&gt; does not need to be sorted.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 13:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620062#M182137</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-26T13:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620084#M182152</link>
      <description>Public Use Micro Files?</description>
      <pubDate>Sun, 26 Jan 2020 18:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620084#M182152</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-26T18:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620085#M182153</link>
      <description>&lt;P&gt;If you are generating synthetic data this may be helpful.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings17/1224-2017.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings17/1224-2017.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 18:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620085#M182153</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-26T18:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620091#M182157</link>
      <description>&lt;P&gt;Wonderful FreelanceReinhard! &amp;nbsp;I have used Option1 in the R language and am avoiding it in SAS because the situation does not allow a formula to be built; but even before trying out your Option 2 I am fascinated with the idea. So I am going to "dig in &amp;nbsp;here" and if I get stuck some place I will ask for more help. In any event, at the end to the road, doing all this inside SAS is a huge development since in my simulation work I often am at a point where the micro data file has several variables with simulated values here and there and it is embedded in a SAS dataset.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 21:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620091#M182157</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-26T21:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620095#M182159</link>
      <description>&lt;P&gt;Thanks for the link Reeza, and yes I am dealing with public use micro data files. My output involves 'patching' information into File A based on patterns in File B that involve networks of predictor variables that both files share (using hopefully reasonable assumptions and supported where feasible with relevant multivariate analysis), so there is quite a bit of 'synthetic stuff' in my records. I expect i will learn some useful ideas from the page to which you are sending me.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 21:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620095#M182159</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-26T21:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620096#M182160</link>
      <description>&lt;P&gt;My goodness Reeza you have sent me to a gold mine! &amp;nbsp;Just starting to read the piece I see the exact philosophy that is driving my work, and my situation is a bit easier in that most of my micro data file comprises values drawn from survey observations. I am going to enjoy learning the procedures covered in that paper. So thanks again!&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 21:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620096#M182160</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-26T21:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620252#M182221</link>
      <description>&lt;P&gt;Hello FreelanceReinhard!&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;Your code (adapted in the direction of my eventual application) ran the first time with no error message. So thanks again, and the code is below. I have a few education questions following the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Create test data */&lt;/P&gt;&lt;P&gt;DATA observations;&lt;/P&gt;&lt;P&gt;INPUT id x1 x2 x3;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;1 3 1 4&lt;/P&gt;&lt;P&gt;2 5 9 2&lt;/P&gt;&lt;P&gt;3 8 0 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* donor distributions for the simulation */&lt;/P&gt;&lt;P&gt;DATA AgeDonorDistribs;&lt;/P&gt;&lt;P&gt;INPUT sig p1&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;p2 &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;p3 ;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;144&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;.1 .2 .5&lt;/P&gt;&lt;P&gt;15000&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;.3 .4 .2&lt;/P&gt;&lt;P&gt;32000&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;.4 .2 .3&lt;/P&gt;&lt;P&gt;43740&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;.6 .1 .1&lt;/P&gt;&lt;P&gt;48600&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;.2 .1 .3&lt;/P&gt;&lt;P&gt;15746400 .2 .3 .2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;/* sig, the ID of an imputation donor distribution,&lt;/P&gt;&lt;P&gt;can also be a vector of categorical variables&lt;/P&gt;&lt;P&gt;that represent respondent attributes -&lt;/P&gt;&lt;P&gt;see &lt;A href="https://support.sas.com/resources/papers/proceedings15/3024-2015.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings15/3024-2015.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.linkedin.com/pulse/sas-hash-tables-patrick-cuba" target="_blank"&gt;https://www.linkedin.com/pulse/sas-hash-tables-patrick-cuba&lt;/A&gt;&lt;/P&gt;&lt;P&gt;N.B. In a real donor distribution we require p1+p2+p3 = 1 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let n=1; /* sample size per ID */&lt;/P&gt;&lt;P&gt;/* n=1 is normal in population simulation, except&lt;/P&gt;&lt;P&gt;where we are setting up sesitivity tests */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA SimulOutput(KEEP=id sampno y);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CALL STREAMINIT(27182818);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;IF _N_=1 THEN DO;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;DECLARE HASH obj(DATASET:'AgeDonorDistribs');&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;obj.DEFINEKEY('sig');&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;obj.DEFINEDATA('p1','p2','p3');&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;obj.DEFINEDONE();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;IF 0 THEN SET AgeDonorDistribs ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;/*&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;What on earth does this do??? */&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;END;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;SET observations;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* compute the signature of the observation now in RAM */&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;sig=2**x1*3**x2*5**x3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* retrieve the correct donor distribution for&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;this particular observation and draw random sample(s).&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;It is a sample of 1 when &amp;amp;n =&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;1 */&lt;/P&gt;&lt;P&gt;IF obj.FIND()=0 THEN&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;DO sampno=1 to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;y=RAND('TABLE', OF p1 p2 p3);&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;OUTPUT;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Questions:&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;(1) Once the collection of simulation-donor distributions is loaded into RAM from an external file, is there some way for me to instructs SAS to bring the table up to the screen so that I can confirm that the loading has happened correctly?&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;(2) I expect exhaust to issue a syntax error message AFTER DO here: " IF obj.FIND()=0 THEN DO sampno=1 to &amp;amp;n;". Why did not do so?&lt;/P&gt;&lt;P&gt;(3) Help me here please: what exactly is this expression doing ? IF obj.FIND()=0 . On the surface, it looks as if an actions to be taken up a condition does not exist (see =0); what I see in the output WORK file that appropriate action seems to have been taken.&lt;/P&gt;&lt;P&gt;(4) What error message will I get when the look-up table signatures contain no match for the computed signature of the just loaded record? (My first question is important here because the failure to match could be caused by a reading error as the look-up table was being brought into RAM).&lt;/P&gt;&lt;P&gt;(5) In "IF 0 THEN SET AgeDonorDistribs ;", what is being evaluated at zero, and why do we point to the donor distributions when the DECLARE JHASH ... has already done that?&lt;/P&gt;&lt;P&gt;Thanks in advance. Your answers will help me to intelligently make big changes in the details for my eventual applications.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 17:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620252#M182221</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-27T17:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620255#M182222</link>
      <description>Apologies for all the "typos"; especially "exhaust" which should be SAS.</description>
      <pubDate>Mon, 27 Jan 2020 17:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620255#M182222</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-27T17:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620330#M182260</link>
      <description>&lt;P&gt;Glad to read that my code worked for you. Please find below the answers to your questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;One possible way: Using the &lt;A href="https://documentation.sas.com/?docsetId=lecompobjref&amp;amp;docsetTarget=n01gpmciy3z1cxn1g0wgwqufwou1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;OUTPUT method&lt;/A&gt; of the SAS hash object you can write the data items of the hash table to a SAS dataset. However, by default, the hash table is not sorted. Its internal sort order is optimized for data retrieval. You can enforce a sort order, though, by specifying the ORDERED&amp;nbsp;argument tag in the declaration of the hash object. To facilitate your check, you will probably want to add the key item (in your case: &lt;FONT face="courier new,courier"&gt;sig&lt;/FONT&gt;) to the list of data items so that it will be part of the output dataset (arbitrarily named &lt;FONT face="courier new,courier"&gt;check_ht&lt;/FONT&gt; below), which you could then directly compare to dataset&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;AgeDonorDistribs&lt;/FONT&gt; (with PROC COMPARE), assuming that this is sorted by &lt;FONT face="courier new,courier"&gt;sig&lt;/FONT&gt; as well. The necessary modifications to your code to prepare this check are highlighted in red below:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE&gt; IF _N_=1 THEN DO;
    DECLARE HASH obj(DATASET:'AgeDonorDistribs'&lt;FONT color="#FF0000"&gt;, ordered:'a'&lt;/FONT&gt;);
    obj.DEFINEKEY('sig');
    obj.DEFINEDATA(&lt;FONT color="#FF0000"&gt;'sig',&lt;/FONT&gt;'p1','p2','p3');
    obj.DEFINEDONE();
 
    IF 0 THEN SET AgeDonorDistribs ;
    &lt;FONT color="#FF0000"&gt;obj.output(dataset:'check_ht');&lt;/FONT&gt;
 END;&lt;/PRE&gt;
&lt;SPAN&gt;Alternatively (and requiring more additional code), you could retrieve all values from the hash object (key value by key value) and write them to the log or output window. I don't think it's worth the effort, but if you ever observe a significant discrepancy between &lt;FONT face="courier new,courier"&gt;check_ht&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;AgeDonorDistribs&lt;/FONT&gt;, please create a new thread about your finding in this forum.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;The FIND method returns 0 if the key value (here: the value of variable &lt;FONT face="courier new,courier"&gt;sig&lt;/FONT&gt; computed immediately before the IF/THEN statement) is found in the hash table. Otherwise the return code (which could be written to a numeric variable &lt;FONT face="courier new,courier"&gt;rc&lt;/FONT&gt;) would be a nonzero integer. So the code is similar to "&lt;FONT face="courier new,courier"&gt;if rc=0 then do&lt;/FONT&gt; ...", which is usual DATA step syntax. The macro variable reference &lt;FONT face="courier new,courier"&gt;&amp;amp;n&lt;/FONT&gt; resolves to 1 (in your example), thus making the DO loop specification complete. Why would you expect a syntax error? As long as &amp;amp;n=1, you could simplify the code and omit variable &lt;FONT face="courier new,courier"&gt;sampno&lt;/FONT&gt; (whose constant value 1 would be redundant).&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;See answer to question 2 above. I understand that the "=0" seems counterintuitive if you're new to the SAS hash object, but that's how the SAS developers defined the return codes of the FIND method.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Currently, no error message would occur. Just the DO loop would not be executed. But, of course, you can add an ELSE branch to the IF/THEN statement and let SAS (in case of a failed search) write a red error message to the log, terminate the DATA step prematurely or do anything else what you deem appropriate.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;That SET statement is never executed because the IF condition 0 is (obviously) not met. Its purpose is that during compilation the variables of dataset&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;AgeDonorDistribs&lt;/FONT&gt; are brought into the program data vector (PDV) and that they don't seem to be uninitialized to the compiler. In this particular case it's only avoiding the unnecessary notes "&lt;FONT face="courier new,courier"&gt;NOTE: Variable p1 is uninitialized.&lt;/FONT&gt;" etc. in the log. Again, it's a somewhat counterintuitive characteristic of the SAS hash object syntax that the reference to &lt;FONT face="courier new,courier"&gt;AgeDonorDistribs&lt;/FONT&gt; in the DATASET argument tag in the DECLARE statement is (in general) not sufficient for these purposes.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/306617"&gt;@LeStatisticien&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Your answers will help me to intelligently make big changes in the details for my eventual applications.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Becoming familiar with the SAS hash object is a much greater endeavor than, say, learning a new function. But it pays off (at least it did for me). Two decent books have been written about this topic (&lt;A href="https://www.sas.com/store/books/categories/usage-and-reference/sas-hash-object-programming-made-easy/prodBK_62230_en.html" target="_blank" rel="noopener"&gt;SAS® Hash Object Programming Made Easy&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://www.sas.com/store/books/categories/examples/data-management-solutions-using-sas-hash-table-operations-a-business-intelligence-case-study/prodBK_69153_en.html" target="_blank" rel="noopener"&gt;Data Management Solutions Using SAS® Hash Table...&lt;/A&gt;). Good luck with the "big changes" you're planning.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620330#M182260</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-27T20:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620449#M182315</link>
      <description>&lt;P&gt;Thanks for excellent help, FreelanceReinhard. I will study your points carefully, and benefit from them as I move the code to the 'next level' for my real-world applications. The two references you passed along are gratefully received, and will be used repeatedly in the months ahead. I welcome this new (to me - old to you) and massive improvement in the SAS functionality.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 09:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/620449#M182315</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-28T09:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Drawing a random sample from arbitrary distributions when the probabilities vary among responden</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/621304#M182645</link>
      <description>&lt;P&gt;This post is a sort of tutorial for those doing selective simulations inside population micro data files, where multiple attributes of a respondent determine the probability distribution used to control a simulation for that person. The underlying strategy is as ‘old as the hills’; but I have not seen an illustration that involves SAS Hash (look-up) tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My file involves simulations for three variables, and they are stacked sets of operations. For each set, &amp;nbsp;I used to move the population file outside SAS, do the work and then bring it back. Now, thanks to FreelanceReinhard and the discussion at &lt;A href="https://support.sas.com/resources/papers/proceedings15/3024-2015.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings15/3024-2015.pdf&lt;/A&gt;, all three steps are done inside SAS, saving a ton of time. So this is huge!&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below deals with the last set of operations only. The experts here will be annoyed at the needless comments; but this post is for people like me who have used SAS for decades and did not know that doing this sort of simulation work was feasible without leaving SAS. So thanks again FreelanceReinhard.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;=========== &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;START IMPUTE ADL_Categ&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;HERE */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA temp3;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;SET sasfiles.simulmar80_ont ;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA ADLCategDonorDistribs;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;INFILE '/folders/myfolders/ADL_Categ DonorDist.csv' DELIMITER=',' DSD ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;INPUT&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;sex ageg pCat0 pCat1 pCat2 ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;/* signature == sex ageg; proportions== pCat0 pCat1 pCat2 */&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;/* A donor file line looks like this: 2,18,0.635780988,0.332386646,0.031832366 .&lt;/P&gt;&lt;P&gt;Both the name and the coding for "sex" and "ageg" must be IDENTICAL&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;between this file and the population file */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* CAUTION ===== run this segment only when you want to reset the seed. */&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;CALL STREAMINIT(0); &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;/* generate seed from system clock */&lt;/P&gt;&lt;P&gt;X = RAND("UNIFORM");&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;=SYSRANDOM;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;See: &lt;A href="https://blogs.sas.com/content/iml/2017/06/01/choose-seed-random-number.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/06/01/choose-seed-random-number.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;*/&lt;/P&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;&lt;P&gt;/* &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;=====&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;IMPORTANT: this is where we set the number of&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;imputations that will be generated (for a given variable)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;for each respondent. We can use a number greater than 1 at n=1 below&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;to bootstrap a confidence interval for the imputed value. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let n=1; /* sample size per simulation (one record one variable) declared as a macro variable */&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&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;&lt;P&gt;/* The simulation is done in this step */&lt;/P&gt;&lt;P&gt;DATA SimulOutput ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CALL STREAMINIT(313777059);&lt;/P&gt;&lt;P&gt;/* Here we set the seed for the random number drawing, */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Now we load into RAM a collection of donor distributions, one for&lt;/P&gt;&lt;P&gt;each unique respondent signature. We load it into a&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;"hash" (or look-up) table.&lt;/P&gt;&lt;P&gt;_N_=1 means the load is executed as soon as the&lt;/P&gt;&lt;P&gt;first observation is brought into RAM */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;IF _N_=1 THEN DO;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;DECLARE HASH obj(DATASET:'ADLCategDonorDistribs');&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;obj.DEFINEKEY('sex','ageg');&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;obj.DEFINEDATA('pCat0','pCat1','pCat2');&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;obj.DEFINEDONE();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;IF 0 THEN SET ADLCategDonorDistribs ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;/*&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;FreelanceReinhard says to leave this alone.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;The SAS coders have not revealed why this is needed here */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;END;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;/* At this point the entire collection&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;of donor distrubutions is in RAM. SAS should prominently offer&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;me a chance to confirm that they have been read (loaded)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;correctly. FreelanceReinhard has sent me the code&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;I can used to retrieve what was read.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SET temp3; /* This is the pop (observations) file. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ADL_Categ2 = ADL_Categ;&lt;/P&gt;&lt;P&gt;/* We are imputing selected values for ADL_Categ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;but we leave the original values unchanged */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Retrieve the correct donor distribution for&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;this particular observation and draw random sample(s).&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;It is a sample of 1 when &amp;amp;n =&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;1 .&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;obj.FIND() searches for the match and when it is found&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;RAND(...) randomly choses 1 (Cat0), 2 (Cat1) or 3 (Cat2)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;under control of the probabilities 'pCat0','pCat1','pCat2' .&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;IF Age80Plus EQ 1 THEN DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF obj.FIND()=0 THEN&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;DO sampno=1 to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;y=RAND('TABLE', OF pCat0 pCat1 pCat2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;IF y EQ 1 THEN ADL_Categ2 = 0;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;IF y EQ 2 THEN ADL_Categ2 = 1 ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;IF y EQ 3 THEN ADL_Categ2 = 2;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;OUTPUT;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* obj.FIND() is a function (method??)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;that causes a search among lines of the donor distrution file&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;to find the one whose signature matches&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;the key declared above. If an eligible line on the PopFile&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;has no matching key on the DistribDonor file, SAS&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;jumps to the next PopFile line. You can use user-defined&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;tables later on to see which eligible lines failed to get&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;an imputation of ADL_Categ2.&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC FREQ ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;TABLES sampno sex ageg y ADL_Categ2 ;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;/* Do these distributions look decent?&lt;/P&gt;&lt;P&gt;Check this before going further.&lt;/P&gt;&lt;P&gt;It may be good to add ageg*ADL_Categ and ageg*ADL_Categ2&lt;/P&gt;&lt;P&gt;for more detailed checking . */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA temp4;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;SET temp3;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;IF Age80Plus EQ 0 ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;ADL_Categ2 = ADL_Categ;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;/* This operation cannot be done where the look-up&lt;/P&gt;&lt;P&gt;table is being used to find key matches. REM. -- records&lt;/P&gt;&lt;P&gt;with non-matches are simply ignored */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA temp5;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;SET temp4 SimulOutput ;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;/* Here we concatenate the two datasets.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;Rem. that in SimulOutput all persons are aged 80+,&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;and in temp4 there are no such persons.&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC FREQ DATA=temp5;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;TABLES sex ageg mar ADL_Categ2&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;ageg*ADL_Categ&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;ageg*ADL_Categ2;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;/* Check that all these look decent. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA sasfiles.Sim_ADLCateg_80_ONT ;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;SET temp5;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;/* This dataset has all the simulations on board */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;IMP:&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;Breakdown of 80-plus to show&lt;/P&gt;&lt;P&gt;properly simulated details for 80-84, 85-89 and 90+ are&lt;/P&gt;&lt;P&gt;in this file for ageg, mar and ADL_Categ2 ONLY.&lt;/P&gt;&lt;P&gt;For all other tabulations, at ages 80-plus show ONE line for 80-plus,&lt;/P&gt;&lt;P&gt;which will be the survey data (not simulation output). */&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 20:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drawing-a-random-sample-from-arbitrary-distributions-when-the/m-p/621304#M182645</guid>
      <dc:creator>LeStatisticien</dc:creator>
      <dc:date>2020-01-30T20:19:05Z</dc:date>
    </item>
  </channel>
</rss>

