<?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 populate a empty dataset with random data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522081#M141689</link>
    <description>&lt;P&gt;Sorry guys for hazy explanation. Yes,&amp;nbsp; I want to have weights between 50 - 300 lbs, sex between M or F, Age between 18-100, Name can be any name (no specification) and height between 2-7 feet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 18 Dec 2018 00:58:47 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2018-12-18T00:58:47Z</dc:date>
    <item>
      <title>how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522051#M141680</link>
      <description>&lt;P&gt;SAS Gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Could you please help me to populate an empty dataset with random data for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set sashelp.class (obs=0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I have empty dataset class, how to populate this dataset with 1000 random observations. Please don't recommend proc iml; (it doesn't work for me and I don't want to download the university edition of SAS)?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 22:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522051#M141680</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2018-12-17T22:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522053#M141682</link>
      <description>&lt;P&gt;How does the source data come into play? Do you want 1000 records that are repeat entries of CLASS or ...? Can you show a small example of what your input data looks like and what you expect as output.&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/139130"&gt;@buddha_d&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;SAS Gurus,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Could you please help me to populate an empty dataset with random data for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data class;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set sashelp.class (obs=0);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I have empty dataset class, how to populate this dataset with 1000 random observations. Please don't recommend proc iml; (it doesn't work for me and I don't want to download the university edition of SAS)?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 22:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522053#M141682</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-17T22:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522054#M141683</link>
      <description>&lt;P&gt;The ideal situation is to have mix and match (repeats and no repeats), but if not then all could be different.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Reeza&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 22:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522054#M141683</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2018-12-17T22:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522055#M141684</link>
      <description>I have no idea of what that means. Please provide a small example.</description>
      <pubDate>Mon, 17 Dec 2018 22:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522055#M141684</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-17T22:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522057#M141686</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Alphabetic List of Variables and Attributes			
#	Variable	Type	Len
3	Age     	Num	8
4	Height	         Num	8
1	Name	         Char	8
2	Sex	        Char	1
5	Weight	        Num	8&lt;/PRE&gt;&lt;P&gt;The sashelp.class data you used as an example has a combination of Numeric and Character type Fields. Now define what do you mean by populating random values for each type.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Few examples :&lt;/P&gt;&lt;P&gt;Do you have a threshold for populating the numeric data ? (values between 100 and 220 for weight etc .?)&lt;/P&gt;&lt;P&gt;Do you have a rule for generating the character data ( Can it be Any value between A-Z for Sex or just the possibility of only M or F ?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 23:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522057#M141686</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-12-17T23:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522079#M141688</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You identified a data set with 5 variables (name age sex height weight)&lt;/LI&gt;
&lt;LI&gt;You apparently want 1,000 "random" observations with those variables.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by "random data"?&amp;nbsp; Do you mean to randomly sample 1,000 draws from sashelp.class (which only has 19 observations)?&amp;nbsp; If so, then you will certainly get repeats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, I guess there are 58,140 possible combinations of values present&amp;nbsp;in sashelp.class (19 NAMEs * 2 SEXs * 6 AGEs * 17 HEIGHTs * 15 WEIGHTs.&amp;nbsp; Do you want sample without replacement from those 58,140?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 00:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522079#M141688</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-18T00:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522081#M141689</link>
      <description>&lt;P&gt;Sorry guys for hazy explanation. Yes,&amp;nbsp; I want to have weights between 50 - 300 lbs, sex between M or F, Age between 18-100, Name can be any name (no specification) and height between 2-7 feet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 00:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522081#M141689</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2018-12-18T00:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522085#M141691</link>
      <description>&lt;P&gt;You want a sample, with no duplicates taken from an array with values ranging as you specified.&amp;nbsp; Think of the array as 4-dimensional.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First dimension (sex) lower bound 1, upper bound 2&lt;/P&gt;
&lt;P&gt;2nd dimension (age)&amp;nbsp;&amp;nbsp;&amp;nbsp; 18:100&lt;/P&gt;
&lt;P&gt;3rd dimension (height)&amp;nbsp; 24:84&amp;nbsp;&amp;nbsp; (in inches)&lt;/P&gt;
&lt;P&gt;4th dimension (weight(=)&amp;nbsp; 50:300&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's a total of 2,541,626 elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, after initializing the array to all zero's, repeat 100 times the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Generate a set of value within the constraints above&lt;/LI&gt;
&lt;LI&gt;See if the corresponding element is still a zero (i.e. unsampled)
&lt;OL&gt;
&lt;LI&gt;If it isn't, repeat until you find a zero.&lt;/LI&gt;
&lt;LI&gt;If it&amp;nbsp;is
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp;mark the corresponding array element - assign it a value of 1&lt;/LI&gt;
&lt;LI&gt;output the record:&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  if 0 then set sashelp.class;

  call streaminit(102985688);

  array smpl {2,18:100,24:84,50:300} _temporary_ (2541626*0);

  do _n_=1 to 100;
    name='NAME_' || put(_n_,z3.);
    do until (smpl{_sx,age,height,weight}=0);
      _sx=rand('integer',1,2);
      age=rand('integer',18,100);
      height=rand('integer',24,84);
      weight=rand('integer',50,300);
    end;
    smpl{_sx,age,height,weight}=1;
    sex=char('MF',_sx);
    output;
  end;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the&amp;nbsp;definition of the SMPL array has 4 dimensions.&amp;nbsp; But instead&amp;nbsp;of just specifying the SIZE of each dimension, it specifies the range.&amp;nbsp; That makes it easy to generate random numbers&amp;nbsp;for age between 18 and 100 an assign it directly to the SMPL array.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 01:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522085#M141691</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-18T01:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522102#M141696</link>
      <description>&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461" target="_self"&gt;mkeintz&lt;/A&gt;&amp;nbsp;. Could you please explain how you got this element number (&lt;/SPAN&gt;&lt;SPAN&gt;2,541,626)?&amp;nbsp; Below is the error I am getting.&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;Here is the Log:&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="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas log.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25767iCE17F4424C27E33D/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas log.PNG" alt="sas log.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 02:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522102#M141696</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2018-12-18T02:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate a empty dataset with random data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522112#M141702</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461" target="_self"&gt;mkeintz&lt;/A&gt;&amp;nbsp;. Could you please explain how you got this element number (&lt;/SPAN&gt;&lt;SPAN&gt;2,541,626)?&amp;nbsp; Below is the error I am getting.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value arrays include&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2 sexes&lt;/P&gt;
&lt;P&gt;83 ages&amp;nbsp;&amp;nbsp; (18:100)&lt;BR /&gt;61 heights (24:84)&amp;nbsp; - in inches&lt;/P&gt;
&lt;P&gt;251 weights (50:300)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although the layout is treated as a 4-dimensional array (read "matrix") the total number of elements is the product: 2,541,626.&amp;nbsp;&amp;nbsp;So&amp;nbsp;the array statement declared the size and upper/lower bounds for each of the 4 dimensions, and then told sas to initialize all&amp;nbsp;2,541,626 cells to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the error messages, I suppose your version of sas (mine is 9.4 TS1M5) hasn't added the "integer" distribution for the RAND function.&amp;nbsp; But you do have the "uniform" distribution.&amp;nbsp; So instead of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	  _sx=rand('integer',1,2);
	  age=rand('integer',18,100);
	  height=rand('integer',24,84);
	  weight=rand('integer',50,300);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      _sx=ceil(rand('uniform',0,2));
      age=ceil(rand('uniform',17,100));
      height=ceil(rand('uniform',23,84));
      weight=ceil(rand('uniform',49,300));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 04:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-a-empty-dataset-with-random-data/m-p/522112#M141702</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-18T04:07:10Z</dc:date>
    </item>
  </channel>
</rss>

