<?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 Using IN= to Create New Column that Tags Data as from Data Set 1, Data Set 2, or Both in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846447#M334619</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to merge two data sets and want to use the IN= statement to create a new column that tags the data as coming from data set 1, data set 2, or both. However, I am finding that despite putting IN= followed by logic statements later in the data step to assign a value for these three conditions, only one value is being written and the "both" value gets overwritten. An example with two data sets (taken from &lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/1746-2018.pdf" target="_self"&gt;this paper&lt;/A&gt; by Joshua Horstman) is attached along with code for my attempt to merge the two data sets by planet and display whether the data came from the planet_size data set, the planet_dist data set, or both. This image shows what I am getting:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-11-26 at 17.19.59.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77737iC18DB85565A7E7C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2022-11-26 at 17.19.59.png" alt="Screenshot 2022-11-26 at 17.19.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note how the data_origin column only has values for 'dist', when in reality the observation for Earth should have a value of 'size' as only the planet_size data set contributed. The output that I would like to obtain is attached along with the code shown below. Any thoughts would be greatly appreciated, thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data work.planet_size;
	input planet $ diam_mi;
datalines;
Earth 7918
Jupiter 86881
Mars 4212
Mercury 3032
Neptune 30599
Saturn 72367
Uranus 31518
Venus 7521
;

data work.planet_dist;
	input planet $ dist_au;
datalines;
Jupiter 4.2
Mars 0.52
Mercury 0.61
Neptune 29.06
Saturn 8.54
Uranus 18.14
Venus 0.28
;

data work.planet_size_dist;
	merge work.planet_size(in=s)
		work.planet_dist(in=d);
	by planet;
	if s and not d then data_origin = 'dist';
	else if d and not s then data_origin = 'size';
	else if s and d then data_origin = 'dist_size';
run;

/* Desired Output */
PLANET 	DIAM_MI 	DIST_AU		data_origin
Earth 	7918 		.		size
Jupiter 86881 		4.2		dist_size
Mars 	4212 		0.52		dist_size
Mercury 3032 		0.61		dist_size
Neptune 30599 		29.06		dist_size
Saturn 	72367 		8.54		dist_size
Uranus 	31518 		18.14		dist_size
Venus 	7521 		0.28		dist_size&lt;/PRE&gt;</description>
    <pubDate>Sat, 26 Nov 2022 23:23:34 GMT</pubDate>
    <dc:creator>ajd555</dc:creator>
    <dc:date>2022-11-26T23:23:34Z</dc:date>
    <item>
      <title>Using IN= to Create New Column that Tags Data as from Data Set 1, Data Set 2, or Both</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846447#M334619</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to merge two data sets and want to use the IN= statement to create a new column that tags the data as coming from data set 1, data set 2, or both. However, I am finding that despite putting IN= followed by logic statements later in the data step to assign a value for these three conditions, only one value is being written and the "both" value gets overwritten. An example with two data sets (taken from &lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/1746-2018.pdf" target="_self"&gt;this paper&lt;/A&gt; by Joshua Horstman) is attached along with code for my attempt to merge the two data sets by planet and display whether the data came from the planet_size data set, the planet_dist data set, or both. This image shows what I am getting:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-11-26 at 17.19.59.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77737iC18DB85565A7E7C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2022-11-26 at 17.19.59.png" alt="Screenshot 2022-11-26 at 17.19.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note how the data_origin column only has values for 'dist', when in reality the observation for Earth should have a value of 'size' as only the planet_size data set contributed. The output that I would like to obtain is attached along with the code shown below. Any thoughts would be greatly appreciated, thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data work.planet_size;
	input planet $ diam_mi;
datalines;
Earth 7918
Jupiter 86881
Mars 4212
Mercury 3032
Neptune 30599
Saturn 72367
Uranus 31518
Venus 7521
;

data work.planet_dist;
	input planet $ dist_au;
datalines;
Jupiter 4.2
Mars 0.52
Mercury 0.61
Neptune 29.06
Saturn 8.54
Uranus 18.14
Venus 0.28
;

data work.planet_size_dist;
	merge work.planet_size(in=s)
		work.planet_dist(in=d);
	by planet;
	if s and not d then data_origin = 'dist';
	else if d and not s then data_origin = 'size';
	else if s and d then data_origin = 'dist_size';
run;

/* Desired Output */
PLANET 	DIAM_MI 	DIST_AU		data_origin
Earth 	7918 		.		size
Jupiter 86881 		4.2		dist_size
Mars 	4212 		0.52		dist_size
Mercury 3032 		0.61		dist_size
Neptune 30599 		29.06		dist_size
Saturn 	72367 		8.54		dist_size
Uranus 	31518 		18.14		dist_size
Venus 	7521 		0.28		dist_size&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Nov 2022 23:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846447#M334619</guid>
      <dc:creator>ajd555</dc:creator>
      <dc:date>2022-11-26T23:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN= to Create New Column that Tags Data as from Data Set 1, Data Set 2, or Both</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846454#M334622</link>
      <description>&lt;P&gt;you need to put a length on data_origin.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tarheel13_0-1669510820996.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77738iE910C5FDC6858BE1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tarheel13_0-1669510820996.png" alt="tarheel13_0-1669510820996.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;it will truncate the value without a proper length statement. try running this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.planet_size_dist;
   length data_origin $9;
   merge work.planet_size(in=s)
      work.planet_dist(in=d);
   by planet;
   if s and not d then data_origin = 'dist';
   else if d and not s then data_origin = 'size';
   else if s and d then data_origin = 'dist_size';
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2022 01:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846454#M334622</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-11-27T01:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN= to Create New Column that Tags Data as from Data Set 1, Data Set 2, or Both</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846457#M334623</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt; , this worked brilliantly!&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2022 03:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-to-Create-New-Column-that-Tags-Data-as-from-Data-Set-1/m-p/846457#M334623</guid>
      <dc:creator>ajd555</dc:creator>
      <dc:date>2022-11-27T03:33:32Z</dc:date>
    </item>
  </channel>
</rss>

