<?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: Adding new variable with values based on conditions from another dataset in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718064#M34713</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
	input x1$;
	datalines;
a
b
c
d
;
run;

data two;
	input x1$;
	datalines;
a
b
run;

proc sql;
	create table three as
		select one.x1,two.x1 as x2,
			case 
				when one.x1 = two.x1 /*STRIP if needed*/
	then 1 else 0 end as z
		from one full join two
			on one.x1 = two.x1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Does the above help, SQL is efficient as there is no previous sort required, but will need creating a third dataset.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2021 23:15:58 GMT</pubDate>
    <dc:creator>qoit</dc:creator>
    <dc:date>2021-02-09T23:15:58Z</dc:date>
    <item>
      <title>Adding new variable with values based on conditions from another dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718059#M34712</link>
      <description>&lt;P&gt;Hello all;&lt;/P&gt;&lt;P&gt;I have two datasets, one and two. dataset two is subset of dataset one with less observations. I want to add a numerical binary variable (z) to dataset one, that the value of z=1 for observations that are in dataset two and z=0 for those observations that are not&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;in dataset two. Appreciate for any help.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input x1 ;
datalines;
...
;
run;

data two;
input x1;
datalines;
...
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Feb 2021 22:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718059#M34712</guid>
      <dc:creator>fatemeh</dc:creator>
      <dc:date>2021-02-09T22:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding new variable with values based on conditions from another dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718064#M34713</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
	input x1$;
	datalines;
a
b
c
d
;
run;

data two;
	input x1$;
	datalines;
a
b
run;

proc sql;
	create table three as
		select one.x1,two.x1 as x2,
			case 
				when one.x1 = two.x1 /*STRIP if needed*/
	then 1 else 0 end as z
		from one full join two
			on one.x1 = two.x1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Does the above help, SQL is efficient as there is no previous sort required, but will need creating a third dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 23:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718064#M34713</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-09T23:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding new variable with values based on conditions from another dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718066#M34714</link>
      <description>&lt;P&gt;Is this based on a single value in the data set or does the whole line need to match? &lt;BR /&gt;You need to provide more details but otherwise, just do a MERGE and look at the IN option. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge one (in=a) two (in=b);
by &amp;lt;you need to fill in&amp;gt;; *you have not specified the problem well enough to indicate what goes here;
if a &amp;amp; b then z=0;
else if b then z=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;See Example 5 in the documentation for more details. &lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1i8w2bwu1fn5kn1gpxj18xttbb0.htm&amp;amp;locale=en#n01jepaobjvwmyn1kd3bghrqo707" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1i8w2bwu1fn5kn1gpxj18xttbb0.htm&amp;amp;locale=en#n01jepaobjvwmyn1kd3bghrqo707&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 23:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Adding-new-variable-with-values-based-on-conditions-from-another/m-p/718066#M34714</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-09T23:21:51Z</dc:date>
    </item>
  </channel>
</rss>

