<?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: copy variable values from one dataset to the other based on a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644838#M192684</link>
    <description>&lt;P&gt;In a DATA step, you merge the two data sets, using BY SNO;&lt;/P&gt;</description>
    <pubDate>Sun, 03 May 2020 14:18:12 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-05-03T14:18:12Z</dc:date>
    <item>
      <title>copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644837#M192683</link>
      <description>&lt;P&gt;I have a dataset 1 as mentioned below&lt;/P&gt;
&lt;P&gt;sno name &lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;ganesh&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;akhila&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;aditya&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;ashok &lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;SREE&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; yash&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have dataset2 as mentioned below&lt;/P&gt;
&lt;P&gt;sno&amp;nbsp; gender&amp;nbsp; &amp;nbsp; age&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;male&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;male&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;26&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; female&amp;nbsp; &amp;nbsp; &amp;nbsp;28&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;male&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, where the sno matches the values from the second table must be copied to the varaibles newvar1 and newvar2 and if not " NA" should appear as mentioned below .&lt;/P&gt;
&lt;P&gt;sno&amp;nbsp; name&amp;nbsp; newvar1&amp;nbsp; newvar2&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; ganesh male 23&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;akhila NA NA&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;aditya male 26&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ashok female 28&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SREE FEMALE 28&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yash NA NA&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644837#M192683</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-05-03T14:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644838#M192684</link>
      <description>&lt;P&gt;In a DATA step, you merge the two data sets, using BY SNO;&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644838#M192684</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-03T14:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644839#M192685</link>
      <description>&lt;P&gt;Run a DATA step MERGE with the in= dataset option for dataset2, and by sno;&lt;/P&gt;
&lt;P&gt;If the in= variable for dataset2 is false, set gender to NA, and let age stay missing (as it is numeric, it can't have a character value). If you really want NA for missing, create a custom format for that.&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644839#M192685</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-03T14:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644840#M192686</link>
      <description>I have done with merge but  in need to compare this for three datasets .So i need a single set of program like using UPDATE and SET</description>
      <pubDate>Sun, 03 May 2020 14:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644840#M192686</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-05-03T14:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644841#M192687</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150852"&gt;@rohithverma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure you want to change the type of the age variable?&lt;/P&gt;
&lt;P&gt;Is it for reporting purpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset1;
	input sno name $;
	datalines;
1 ganesh
2 akhila
3 aditya
4 ashok 
5 SREE
6 yash
;
run;

data dataset2;
	input sno gender $ age;
	datalines;
1 male 23
3 male 26
4 female 28
5 male 29
;
run;

data want (drop=agen);
	merge dataset1 (in=x) dataset2 (in=y rename=(age = agen));
	by SNO;
	if x=1;
	age = put(agen,best.);
	if y=0 then do;
		age = "NA";
		gender = "NA";
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 May 2020 14:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644841#M192687</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-03T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644842#M192688</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150852"&gt;@rohithverma&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have done with merge but in need to compare this for three datasets .So i need a single set of program like using UPDATE and SET&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your initial posts mentions only TWO datasets. Make up your mind.&lt;/P&gt;
&lt;P&gt;What you described in the OP is a MERGE, period.&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644842#M192688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-03T14:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: copy variable values from one dataset to the other based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644843#M192689</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150852"&gt;@rohithverma&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have done with merge but in need to compare this for three datasets .So i need a single set of program like using UPDATE and SET&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;MERGE is the perfect command here, not UPDATE or SET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have to have NA? MERGE will create missing values, that ought to be sufficient for any reasonable purpose.&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-variable-values-from-one-dataset-to-the-other-based-on-a/m-p/644843#M192689</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-03T14:36:12Z</dc:date>
    </item>
  </channel>
</rss>

