<?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: Using two data sets to form another data set (no combine or merge) in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373122#M2887</link>
    <description>SQL is the easiest way to solve this. See &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; solution. A SAS data step doesn't process data all at once, it reads a line at a time.But this means it doesn't have information on the records either ahead or below, though there are ways around that. But in general, in SAS, an array is simply a way to reference variables in the same row.</description>
    <pubDate>Wed, 05 Jul 2017 01:50:25 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-07-05T01:50:25Z</dc:date>
    <item>
      <title>Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373109#M2884</link>
      <description>&lt;P&gt;Thank you very much for your thoughts in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use SAS 9.4. I have a data set with 17170 rows, and I want to create an array based on one of variables in this data set. Then, I want to use that array in another data set to filter its observations (i.e., more than 1 million observations). So, if any observation in the new data set is not among those 17170 different values, then that specific row has to be removed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I used (where libsas refers to my local directory):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data libsas.new_data;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set libsas.data1; /* data1 has 17170 rows */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;array schedule(*) X1; /* I want to form array "schedule" based on variable X1 in data1 */&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set libsas.data2; /* data2 is the second data set in which I&amp;nbsp;want to filter observations */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if X2&amp;nbsp;in schedule; /* X2 is the variable in data2 where I want to filter observations */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, what I get is a data with 17170 rows (i.e., the same size as my first data), while it should be much more that. Would you please help me to understand what's wrong? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 00:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373109#M2884</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-07-05T00:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373112#M2885</link>
      <description>&lt;P&gt;Your array contains one element named X1. &amp;nbsp;It does not contain thousands of elements, just one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS contains many ways to select matches. &amp;nbsp;Here is one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table libsas.new_data as select * from libsas.data2&lt;/P&gt;
&lt;P&gt;where x2 in (select distinct x1 from libsas.data1);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 00:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373112#M2885</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-05T00:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373113#M2886</link>
      <description>&lt;P&gt;You got that result because that is the way SAS works unless told otherwise. If you had read both datasets within separate DO UNTIL loops, you'd have gotten what you wanted. e.g.,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data data1;
  input x1;
  cards;
3
4
5
7
;

data data2;
  input x2 z;
  cards;
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
3 3
4 4
5 5
6 6
7 7
3 3
4 4
5 5
6 6
7 7
;

data new_data (drop=i x1);
  array schedule(20000) _temporary_; 
  do until (eof1);
    set data1 end=eof1;
    i+1;
    schedule(i)=x1;
  end;
  do until (eof2);
    set data2 end=eof2;
    if X2 in schedule then output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 00:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373113#M2886</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-05T00:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373122#M2887</link>
      <description>SQL is the easiest way to solve this. See &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; solution. A SAS data step doesn't process data all at once, it reads a line at a time.But this means it doesn't have information on the records either ahead or below, though there are ways around that. But in general, in SAS, an array is simply a way to reference variables in the same row.</description>
      <pubDate>Wed, 05 Jul 2017 01:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373122#M2887</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-05T01:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373132#M2888</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147550"&gt;@Alireza_Boloori&lt;/a&gt;'s subject line indicated NO COMBINE of MERGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I don't know if I'd say the SQL solution is easier but, in this case, should run about 100 times faster than the datastep approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 02:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/373132#M2888</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-05T02:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/375892#M3006</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 01:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/375892#M3006</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-07-14T01:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/375893#M3007</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;Thank you for your feedback!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 01:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/375893#M3007</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-07-14T01:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using two data sets to form another data set (no combine or merge)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/375894#M3008</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;Thank you for your feedback! I was thinking the same about using SQL. I guess I have to start learning it.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 01:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Using-two-data-sets-to-form-another-data-set-no-combine-or-merge/m-p/375894#M3008</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-07-14T01:42:46Z</dc:date>
    </item>
  </channel>
</rss>

