<?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: Merging one variable in a data set with all the values in a different data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396090#M278101</link>
    <description>&lt;P&gt;Yes, looks like the unconditional execution is the culprit?&lt;/P&gt;
&lt;PRE&gt;23         data _null_;
24           set data1;
25           if _n_=1 then set data2;
26         run;

NOTE: There were 100000000 observations read from the data set WORK.DATA1.
NOTE: There were 1 observations read from the data set WORK.DATA2.
NOTE: DATA statement used (Total process time):
      real time           3.43 seconds
      cpu time            3.40 seconds
      

27         
28         data _null_;
29           set data1;
30         if _n_=1 then  set data2 point=_n_;
31         
32         run;

NOTE: There were 100000000 observations read from the data set WORK.DATA1.
NOTE: DATA statement used (Total process time):
      real time           3.48 seconds
      cpu time            3.44 seconds&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Sep 2017 20:32:48 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2017-09-14T20:32:48Z</dc:date>
    <item>
      <title>Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396056#M278092</link>
      <description>&lt;P&gt;i have two datasets namely data1 and data2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data1;&lt;/P&gt;&lt;P&gt;input x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;24&lt;/P&gt;&lt;P&gt;45&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data data2;&lt;/P&gt;&lt;P&gt;input c;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want another dataset namely data3 to contain&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;x &amp;nbsp; &amp;nbsp; c&lt;/P&gt;&lt;P&gt;&amp;nbsp; 12 &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&amp;nbsp; 24 &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&amp;nbsp; 45 &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated. I'm currently using sas 9.4 on windows.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396056#M278092</guid>
      <dc:creator>variathu</dc:creator>
      <dc:date>2017-09-14T19:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396065#M278093</link>
      <description>&lt;PRE&gt;proc sql;
  create table want as
  select data1.x, data2.c
  from data1,data2
  ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396065#M278093</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-14T19:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396068#M278094</link>
      <description>&lt;P&gt;proc sql carterian or datastep one to one merge:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data data1;&lt;BR /&gt;input x;&lt;BR /&gt;cards;&lt;BR /&gt;12&lt;BR /&gt;24&lt;BR /&gt;45&lt;BR /&gt;;&lt;BR /&gt;data data2;&lt;BR /&gt;input c;&lt;BR /&gt;cards;&lt;BR /&gt;10&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select x,c&lt;BR /&gt;from data1,data2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set data1;&lt;BR /&gt;if _n_=1 then set data2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396068#M278094</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-14T19:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396069#M278095</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
input x;
cards;
12
24
45
;
data data2;
input c;
cards;
10
;

proc sql;
   create table data3 as
   select data1.*, data2.c
   from data1 join data2 on c;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396069#M278095</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-09-14T19:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396070#M278096</link>
      <description>&lt;P&gt;You can take advantage of the fact the any variables in the program data vector that result from a SET (or MERGE) statement are automatically ratained until the next iteration of a SET (or MERGE) of the same data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So make sure you only SET DATA2 for one iteraction of the data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
  set data1;
  if _n_=1 then set data2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above only reads in DATA2 in the first iteration of the data step, while DATA1 is read in for every iteration.&amp;nbsp; The data step ends when a SET attempts to read beyond the end of an incoming data set.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396070#M278096</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-14T19:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396071#M278097</link>
      <description>&lt;P&gt;And the data step method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data1;
if _n_=1 then set data2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165081"&gt;@variathu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;i have two datasets namely data1 and data2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data data1;&lt;/P&gt;
&lt;P&gt;input x;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;P&gt;24&lt;/P&gt;
&lt;P&gt;45&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;data data2;&lt;/P&gt;
&lt;P&gt;input c;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i want another dataset namely data3 to contain&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;x &amp;nbsp; &amp;nbsp; c&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 12 &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 24 &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 45 &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated. I'm currently using sas 9.4 on windows.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396071#M278097</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-14T19:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396076#M278098</link>
      <description>&lt;P&gt;thank you very much &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 19:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396076#M278098</guid>
      <dc:creator>variathu</dc:creator>
      <dc:date>2017-09-14T19:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396077#M278099</link>
      <description>&lt;P&gt;Another data step approach&amp;nbsp;besides the classical solution that many have mentioned:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data1;
n=1;
set data2 point= n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 20:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396077#M278099</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-09-14T20:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396081#M278100</link>
      <description>&lt;P&gt;I believe there is a performance problem with the direct-access method (set data2 point=n;).&amp;nbsp; The first DATA _NULL_ below took 5.1 seconds on my windows machine, while the second (using the "point=" technique) took 28.8 seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
  do x=1 to 100000000;output;end;
run;
data data2;
  c=0;
run;

data _null_;
  set data1;
  if _n_=1 then set data2;
run;

data _null_;
  set data1;
  retain n 1;
  set data2 point=n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 20:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396081#M278100</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-14T20:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396090#M278101</link>
      <description>&lt;P&gt;Yes, looks like the unconditional execution is the culprit?&lt;/P&gt;
&lt;PRE&gt;23         data _null_;
24           set data1;
25           if _n_=1 then set data2;
26         run;

NOTE: There were 100000000 observations read from the data set WORK.DATA1.
NOTE: There were 1 observations read from the data set WORK.DATA2.
NOTE: DATA statement used (Total process time):
      real time           3.43 seconds
      cpu time            3.40 seconds
      

27         
28         data _null_;
29           set data1;
30         if _n_=1 then  set data2 point=_n_;
31         
32         run;

NOTE: There were 100000000 observations read from the data set WORK.DATA1.
NOTE: DATA statement used (Total process time):
      real time           3.48 seconds
      cpu time            3.44 seconds&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 20:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396090#M278101</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-09-14T20:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Merging one variable in a data set with all the values in a different data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396095#M278102</link>
      <description>&lt;P&gt;Take the advantage of automatic retention. Read pitfalls of automatic retention in this paper (&lt;A href="http://analytics.ncsu.edu/sesug/2015/CC-34.pdf" target="_blank"&gt;http://analytics.ncsu.edu/sesug/2015/CC-34.pdf&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 20:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-one-variable-in-a-data-set-with-all-the-values-in-a/m-p/396095#M278102</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-09-14T20:39:01Z</dc:date>
    </item>
  </channel>
</rss>

