<?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 data based on (variable names from 1 data file) and (variables value from another data f in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330883#M74305</link>
    <description>&lt;P&gt;Hi MKeintz,&lt;/P&gt;
&lt;P&gt;The current code eliminates duplicate record from Fulldata.&lt;BR /&gt;I actually want to have that duplicate for each condition it satisfies.&lt;/P&gt;
&lt;P&gt;In the below data, I add the last record (15) and it should be in both condition.&lt;/P&gt;
&lt;P&gt;I am not sure how to change your code to get it.&lt;/P&gt;
&lt;P&gt;Can you help me?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HCC&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data condition; &lt;BR /&gt;input condition_ID cond1 :$1. value1 cond2 :$1. value2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 4 b 5&lt;BR /&gt;2 c 1 d 2&lt;BR /&gt;;run;&lt;BR /&gt;data FULLDATA; &lt;BR /&gt;input date a b c d ;&lt;BR /&gt;datalines;&lt;BR /&gt;11 4 5 1 1&lt;BR /&gt;12 4 5 2 5&lt;BR /&gt;13 4 1 2 6&lt;BR /&gt;14 8 3 1 2&lt;BR /&gt;15 4 5 1 2&lt;BR /&gt;;run;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 16:10:58 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2017-02-08T16:10:58Z</dc:date>
    <item>
      <title>Merging data based on (variable names from 1 data file) and (variables value from another data file)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330374#M74099</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I have a FULL_data file in which each date has a number of characteristics.&lt;/P&gt;
&lt;P&gt;I have another condition file that specifies condition for a give 2 characteristic value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For any condition in condition file, I want to pull all date from FULL_data that meet this condition.&lt;/P&gt;
&lt;P&gt;(in my real work, the condition could be 4 or 5 characteristics )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know how to get that kind of merge.&lt;/P&gt;
&lt;P&gt;Any help is very much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;BR /&gt;The WANT file&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;condition_ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;condt1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;value1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;cond2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;value2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;date&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;a&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;b&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;11&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;a&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;b&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;c&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;d&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;14&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data FULLDATA; &lt;BR /&gt;input date a b c d ;&lt;BR /&gt;datalines;&lt;BR /&gt;11 4 5 1 1&lt;BR /&gt;12 4 5 2 5&lt;BR /&gt;13 4&amp;nbsp;1 2 6&lt;BR /&gt;14 8 3 1 2&lt;BR /&gt;;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data condition; &lt;BR /&gt;input condition_ID cond1 $ value1 cond2 $ value2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 4 b 5&lt;BR /&gt;2 c 1 d 2&lt;BR /&gt;;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*************************&lt;/P&gt;
&lt;P&gt;Also, I want to have the WANT file for all records that meet 1 of the 2 conditions (OR), please give me a hint if it is not long.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
*After getting the condition-combination file,
this code will help to merge the condition-combination file with the Full data (retunr) file

In the output file, each condition has all record that meet it. and can be use to analyze quality of condition;


data FULLDATA; 
input date a b c d ;
datalines;
11 4 5 1 1
12 4 5 2 5
13 0 1 2 2
14 8 5 1 2
20 4 5 1 2
;run;
 
data condition; 
input condition_ID cond1 $ value1 cond2 $ value2;
datalines;
1 a 4 b 5
2 c 1 d 2
;run;

******************************************************************************************
*Combination of AND condition1 and condition2;

filename tmp temp;
data _null_;
  set condition end=last_cond;
  file tmp;
	put 'if (' cond1 '=' value1 'AND ' cond2 '=' value2 ')'
	' then do; condition_id=' condition_id '; output;end;' ;
	*if last_cond=0  then put 'else';
run;

options source2;
data want_and;
  set fulldata;
  %include tmp;
run;
proc sort data=want_and; by condition_id date;run;

		*look into the temfile, the second code is like that;
		data want2;
		  set fulldata;
		if (a =4 and b =5)  then do; condition_id=1 ; output;end;
		if (c =1 and d =2)  then do; condition_id=2 ; output;end;
		run;

******************************************************************************************
*Combination of OR condition1 and condition2;

filename tmp temp;
data _null_;
  set condition end=last_cond;
  file tmp;
	put 'if (' cond1 '=' value1 'OR ' cond2 '=' value2 ')' 
	' then do; condition_id=' condition_id '; output;end;' ;
	*if last_cond=0  then put 'else';
run;


options source2;
data want_or;
  set fulldata;
  %include tmp;
run;
proc sort; by condition_id date;run;

		*look into the temfile, the second code is like that;
		data want2;
		  set fulldata;
		if (a =4 OR b =5)  then do; condition_id=1 ; output;end;
		if (c =1 OR d =2)  then do; condition_id=2 ; output;end;
		run;
		proc sort; by condition_id date;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330374#M74099</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-14T18:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330381#M74104</link>
      <description>&lt;P&gt;Use&amp;nbsp; sql&amp;nbsp; "select into :macrovar" to construct the where condition from the CONDITION dataset. Then use it in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select distinct '(' || catx('=',cond1,value1) || ' and ' || catx('=',cond2,value2) || ')'
     into  :cond
     separated by ' or '
   from condition;
quit;

%put &amp;amp;=cond;
data want;
 set fulldata;
 where &amp;amp;cond ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And change the "AND" to "OR" in the&amp;nbsp; select distinct expression to satisfy your 2nd requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 04:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330381#M74104</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-07T04:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330662#M74226</link>
      <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder if there is any way to get the &amp;nbsp;Condition_ID in the want file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 23:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330662#M74226</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-07T23:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330676#M74233</link>
      <description>&lt;P&gt;Since my condition file is large, I create the below marco to run 1 condition at a time.&lt;/P&gt;
&lt;P&gt;I wonder how I can tell SAS to do the: &amp;nbsp;DO i=1 to "END of File" in the first step.&lt;/P&gt;
&lt;P&gt;Also, is there any way to include the condition_id from the original file into the Want file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro cond;
	%do i=1 %to 2;	*HOW TO MAKE IT: i=1 to END OF FILE ;
		data single_condition; set condition;
		if _N_=&amp;amp;i;
		run;
 
		proc sql ;
		   select distinct  '(' || catx('=',cond1,value1) || ' and ' || catx('=',cond2,value2) || ')'
		     into  :cond
		     separated by ' or '
		   from single_condition;
		quit;

		%put &amp;amp;=cond;
			data want_temp;
			 set fulldata;
			 where &amp;amp;cond ;
			 condition_id=&amp;amp;i; *I have to get the Condition_ID manually instead of pulling it from original file;
			run;

		%if &amp;amp;i=1 %then %do;
		data want; set want_temp;
		%end;
		%else %do;
		data want; set want want_temp;
		%end;
	%end;
%mend;

%cond;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2017 00:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330676#M74233</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-08T00:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330690#M74239</link>
      <description>&lt;P&gt;If (1) there are too many conditions in the CONDITION datast, and (2) you want to label conditions, then you could forget the SQL approach and use a DATA _NULL_ step to write out a series of statements like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if&amp;nbsp;&amp;nbsp; x1=1 and y1=1 then condition_id=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else &amp;nbsp; if&amp;nbsp;&amp;nbsp; x2=12and y2=12then condition_id=2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for use in the "data want" step.&amp;nbsp; Then a subsetting if "if condition_id&amp;gt;=1" gets you what you want.&amp;nbsp; There is definitely no need to iterate through the conditions, assuming they are mutually exclusive:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename tmp temp;
data _null_;
  set condition end=last_cond;
  file tmp;
  put 'if ' cond1 '=' value1 'and ' cond2 '=' value2  
      ' then condition_id=' condition_id ';' @;
  if last_cond=0  then put 'else';
run;

options source2;
data want;
  set fulldata;
  %include tmp;
  if condition_id &amp;gt;=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The "filename tmp temp" says to assign the name "TMP" to&amp;nbsp;a temporary file (to be automatically deleted at end of sas session.&lt;/LI&gt;
&lt;LI&gt;The FILE TMP tells SAS that the PUT statements will write to TMP in the first DATA step&lt;/LI&gt;
&lt;LI&gt;The "%include tmp;" statement tells sas to read statement from the TMP file&amp;nbsp; (and the "options source2" statement tells SAS to print to the log any %INCLUDEd statements, so you can see what it happening.&lt;/LI&gt;
&lt;LI&gt;If a record satisfies multiple conditions, only the first one will be identified in this program.&amp;nbsp; (You loop program would identify them all - and would also duplicate the corresponding records from FULLDATA.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 08 Feb 2017 02:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330690#M74239</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-08T02:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330694#M74242</link>
      <description>I want to thank you first for details explanation. &lt;BR /&gt;I cannot comprehend it as I am on call right now.&lt;BR /&gt;I will study it.&lt;BR /&gt;HHC&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Feb 2017 02:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330694#M74242</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-08T02:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330883#M74305</link>
      <description>&lt;P&gt;Hi MKeintz,&lt;/P&gt;
&lt;P&gt;The current code eliminates duplicate record from Fulldata.&lt;BR /&gt;I actually want to have that duplicate for each condition it satisfies.&lt;/P&gt;
&lt;P&gt;In the below data, I add the last record (15) and it should be in both condition.&lt;/P&gt;
&lt;P&gt;I am not sure how to change your code to get it.&lt;/P&gt;
&lt;P&gt;Can you help me?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HCC&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data condition; &lt;BR /&gt;input condition_ID cond1 :$1. value1 cond2 :$1. value2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 4 b 5&lt;BR /&gt;2 c 1 d 2&lt;BR /&gt;;run;&lt;BR /&gt;data FULLDATA; &lt;BR /&gt;input date a b c d ;&lt;BR /&gt;datalines;&lt;BR /&gt;11 4 5 1 1&lt;BR /&gt;12 4 5 2 5&lt;BR /&gt;13 4 1 2 6&lt;BR /&gt;14 8 3 1 2&lt;BR /&gt;15 4 5 1 2&lt;BR /&gt;;run;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330883#M74305</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-08T16:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330896#M74308</link>
      <description>&lt;P&gt;To get such "duplicates"&amp;nbsp;change these two lines in the first data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;put&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'if '&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cond1 &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'='&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; value1 &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'and '&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cond2 &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'='&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; value2 &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; ' then condition_id='&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; condition_id &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;';'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; @;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; last_cond=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;put&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'else'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;put&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'if '&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cond1 &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'='&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; value1 &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'and '&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cond2 &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'='&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; value2 &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;' then do; condition_id='&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; condition_id &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'; output;end;'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And in the second data step,&amp;nbsp;remove this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; condition_id &amp;gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result: if a single record satisfies multiple conditions, it will be output multiple times.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330896#M74308</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-08T16:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330907#M74314</link>
      <description>&lt;P&gt;It works now, Mkeintz!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is a powerful approach, I don't know that kind of method before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can read the tmp file to see what the "if then" command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically, the %include tmp will&amp;nbsp;turn into this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  set fulldata;
if a =4 and b =5  then condition_id=1 ;if c =1 and d =2  then condition_id=2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But where the Merge happen? I do not see something like that. Where it is built in your code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want1;
  set fulldata;
if  a =4 and b =5 ;
run;

data want2;
  set fulldata;
if  c =1 and d =2  ;
run;

data want; set want1 want2;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330907#M74314</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-08T16:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330946#M74326</link>
      <description>&lt;P&gt;xxx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;It works now, Mkeintz!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is a powerful approach, I don't know that kind of method before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can read the tmp file to see what the "if then" command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically, the %include tmp will&amp;nbsp;turn into this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  set fulldata;
if a =4 and b =5  then condition_id=1 ;if c =1 and d =2  then condition_id=2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But where the Merge happen? I do not see something like that. Where it is built in your code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want1;
  set fulldata;
if  a =4 and b =5 ;
run;

data want2;
  set fulldata;
if  c =1 and d =2  ;
run;

data want; set want1 want2;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No.&amp;nbsp; Itr will turn into:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set fulldata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if a=4 and b=5 then do; condition_id=1; output; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if&amp;nbsp;c=1 and&amp;nbsp;d=2 then do; condition_id=2; output; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice there is an OUTPUT statement for every successful IF test.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 18:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/330946#M74326</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-08T18:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data based on (variable names from 1 data file) and (variables value from another data f</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/331053#M74360</link>
      <description>&lt;P&gt;that's output command is so good.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 02:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-based-on-variable-names-from-1-data-file-and/m-p/331053#M74360</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-02-09T02:28:09Z</dc:date>
    </item>
  </channel>
</rss>

