<?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: Create a new variable to a merged dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-a-merged-dataset/m-p/607158#M176413</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;data notpurch;
	merge invt_sorted (in=InInvent) pur_sorted (in=inPurch);
	by Model;
	if missing(Quantity) then Status = "Not Sold";
	else Status = "Sold";
	&lt;STRONG&gt;&lt;FONT color="#ff00ff" size="5"&gt;keep Model Price;&lt;/FONT&gt;&lt;/STRONG&gt;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your KEEP statement says &lt;STRONG&gt;not&lt;/STRONG&gt; to keep the STATUS variable.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 00:23:34 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-11-26T00:23:34Z</dc:date>
    <item>
      <title>Create a new variable to a merged dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-a-merged-dataset/m-p/606689#M176209</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to merge 2 datasets and then create a new variable in the merged dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new variable is Status where if any model in Inventory dataset does not appear in Purchase dataset, Status would be "Not Sold", otherwise Status is "Sold".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I wrote it as if Quantity is missing, then Status ="Not Sold", else Status = "Sold".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Sort Inventory and Purchase datasets by Model*/
proc sort data=BSTA445.inventory out=invt_sorted;
by Model;
run;

proc sort data=BSTA445.purchase out=pur_sorted;
by Model;
run;


/*Merge 2 sorted datasets*/
data notpurch;
	merge invt_sorted (in=InInvent) pur_sorted (in=inPurch);
	by Model;
	if missing(Quantity) then Status = "Not Sold";
	else Status = "Sold";
	keep Model Price;
run;

title "List of unpurchased Models and respective Prices";
proc print data=notpurch noobs;
run;
title;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't know why in the merged dataset, there is no new variable created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please explain what has gone wrong in my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2019 17:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-a-merged-dataset/m-p/606689#M176209</guid>
      <dc:creator>jamieflynn</dc:creator>
      <dc:date>2019-11-23T17:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable to a merged dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-a-merged-dataset/m-p/607158#M176413</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;data notpurch;
	merge invt_sorted (in=InInvent) pur_sorted (in=inPurch);
	by Model;
	if missing(Quantity) then Status = "Not Sold";
	else Status = "Sold";
	&lt;STRONG&gt;&lt;FONT color="#ff00ff" size="5"&gt;keep Model Price;&lt;/FONT&gt;&lt;/STRONG&gt;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your KEEP statement says &lt;STRONG&gt;not&lt;/STRONG&gt; to keep the STATUS variable.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 00:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-a-merged-dataset/m-p/607158#M176413</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-26T00:23:34Z</dc:date>
    </item>
  </channel>
</rss>

