<?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 Macro for stratified sample in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740411#M231289</link>
    <description>&lt;P&gt;I am new to SAS and would like any help for the following:&lt;/P&gt;&lt;P&gt;I have one dataset "table1":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data table1;
  input id $ yearmonth:yymmn6. var1 $ var2 var3 Target;
  format yearmonth yymmn6.;
datalines;
A 202002 xxx 1 2 1
B 202004 zz 2 23 1
C 202011 ee 4 4 1
D 202011 ff 5 5 1
E 202103 tt 6 6 1
F 202103 aa 9 89 1
;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;And other dataset "table2":&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data table2;
  input id $ yearmonth:yymmn6. var1 $ var2 var3 Target;
  format yearmonth yymmn6.;
datalines;
E 202002 aac 23 13 0
F 202004 jsk 4 14 0
A 202011 skal 5 18 0
F 202011 aks 9 13 0
B 202103 xka 1 7 0
G 202103 als 12 9 0
;&lt;/PRE&gt;&lt;P&gt;And I would like to get a stratified sample from table2 by yearmonth ("Want" table) but with following restrictions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I cannot have same id in table2 that i have in table1&lt;/LI&gt;&lt;LI&gt;I cannot have duplicated id's in want table from table 2 after stratified sample (in table 2 they are duplicated because they can be in two different months)&lt;/LI&gt;&lt;LI&gt;I would like to choose the dimension of the stratified sample (n) to achieve the following:&lt;BR /&gt;&lt;UL&gt;&lt;LI&gt;appending the dataset1 and dataset2 the count of id of Target 0 data (coming from dataset2) should be 80% of the total data&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The output would then be :&lt;/P&gt;&lt;PRE&gt;id  yearmonth   Var1    Var2    Var3    Target
A   202002      xxx     1        2       1
B   202004      zz      2       23       1
C   202011      ee      4        4       1
D   202011      ff      5        5       1
E   202103      tt      6        6       1
F   202103      aa      9       89       1
G   202103      als     12       9       0&lt;/PRE&gt;&lt;P&gt;Any help would be very much appreciated!&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 09:05:35 GMT</pubDate>
    <dc:creator>msf2021</dc:creator>
    <dc:date>2021-05-11T09:05:35Z</dc:date>
    <item>
      <title>Macro for stratified sample</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740411#M231289</link>
      <description>&lt;P&gt;I am new to SAS and would like any help for the following:&lt;/P&gt;&lt;P&gt;I have one dataset "table1":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data table1;
  input id $ yearmonth:yymmn6. var1 $ var2 var3 Target;
  format yearmonth yymmn6.;
datalines;
A 202002 xxx 1 2 1
B 202004 zz 2 23 1
C 202011 ee 4 4 1
D 202011 ff 5 5 1
E 202103 tt 6 6 1
F 202103 aa 9 89 1
;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;And other dataset "table2":&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data table2;
  input id $ yearmonth:yymmn6. var1 $ var2 var3 Target;
  format yearmonth yymmn6.;
datalines;
E 202002 aac 23 13 0
F 202004 jsk 4 14 0
A 202011 skal 5 18 0
F 202011 aks 9 13 0
B 202103 xka 1 7 0
G 202103 als 12 9 0
;&lt;/PRE&gt;&lt;P&gt;And I would like to get a stratified sample from table2 by yearmonth ("Want" table) but with following restrictions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I cannot have same id in table2 that i have in table1&lt;/LI&gt;&lt;LI&gt;I cannot have duplicated id's in want table from table 2 after stratified sample (in table 2 they are duplicated because they can be in two different months)&lt;/LI&gt;&lt;LI&gt;I would like to choose the dimension of the stratified sample (n) to achieve the following:&lt;BR /&gt;&lt;UL&gt;&lt;LI&gt;appending the dataset1 and dataset2 the count of id of Target 0 data (coming from dataset2) should be 80% of the total data&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The output would then be :&lt;/P&gt;&lt;PRE&gt;id  yearmonth   Var1    Var2    Var3    Target
A   202002      xxx     1        2       1
B   202004      zz      2       23       1
C   202011      ee      4        4       1
D   202011      ff      5        5       1
E   202103      tt      6        6       1
F   202103      aa      9       89       1
G   202103      als     12       9       0&lt;/PRE&gt;&lt;P&gt;Any help would be very much appreciated!&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 09:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740411#M231289</guid>
      <dc:creator>msf2021</dc:creator>
      <dc:date>2021-05-11T09:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for stratified sample</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740418#M231291</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;you get the output with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE want AS
      SELECT *
      FROM table1 
      UNION CORRESPONDING 
      (SELECT * 
       FROM table2 
       WHERE ID not in
         (SELECT ID 
          FROM table1)
      )
   ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;I do not understand what you mean with:
&lt;P class="1620725346804"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381594"&gt;@msf2021&lt;/a&gt;&lt;SPAN style="font-size: 14px;"&gt;&amp;nbsp;wrote:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="1620725346804"&gt;&lt;SPAN style="font-size: 14px;"&gt;I would like to choose the dimension of the stratified sample (n) to achieve the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="1620725346804"&gt;&lt;SPAN style="font-size: 14px;"&gt;appending the dataset1 and dataset2 the count of id of Target 0 data (coming from dataset2) should be 80% of the total data&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 11 May 2021 09:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740418#M231291</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-05-11T09:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for stratified sample</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740419#M231292</link>
      <description>Hi! In that way i am not having a stratified sample. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;What i mean is i want to get a new dataset "want" that basically is the appendix of dataset1 and the sample (stratified) from dataset2. And i want that the rows in the appendix that come from dataset2 represent 20% of total rows. I hope that i was clear enough, if not, let me know &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 11 May 2021 09:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740419#M231292</guid>
      <dc:creator>msf2021</dc:creator>
      <dc:date>2021-05-11T09:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for stratified sample</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740429#M231293</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;nope it's not clear to me. Try to post a most explicit example of what you would like to achieve and how you would select the rows to display if the rows from dataset2 exceed the 20% of total rows.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 10:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740429#M231293</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-05-11T10:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for stratified sample</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740507#M231333</link>
      <description>&lt;P&gt;Are you going to add selection probabilities or weights to this sample?&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 15:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-stratified-sample/m-p/740507#M231333</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-11T15:02:48Z</dc:date>
    </item>
  </channel>
</rss>

