<?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 How to transfer a field with different values to another table (like a left join with condition) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-a-field-with-different-values-to-another-table/m-p/693919#M211604</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I show you what I want to do. I have to tables: have1 and have2 and I want to have the table "want". If date of have2 is between start_date and end_date I want to copy this field&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you help me with this?&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
informat Start_Date End_Date ddmmyy10.;
format Start_Date End_Date ddmmyy10.;
input id  Start_Date  End_Date;
datalines;
10 08/02/2020 07/03/2020
10 02/10/2020 18/10/2020
;;;;
run;
data have2;
infile datalines delimiter=',';
informat Date ddmmyy10.;
format Date  ddmmyy10.;
input id  Date  ;
datalines;
10,01/01/20
10,15/02/20
10,01/04/20
10,05/05/20
10,05/10/20
;;;;
run;
data want;
infile datalines delimiter=',';
informat Date Start_Date End_Date ddmmyy10.;
format Date Start_Date End_Date ddmmyy10.;
input id  Date  Start_Date  End_Date;
datalines;
10,01/01/20,.,.
10,15/02/20,08/02/2020,07/03/2020
10,01/04/20,.,.
10,05/05/20,.,.
10,05/10/20,02/10/2020,18/10/2020
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 23 Oct 2020 20:29:42 GMT</pubDate>
    <dc:creator>t34</dc:creator>
    <dc:date>2020-10-23T20:29:42Z</dc:date>
    <item>
      <title>How to transfer a field with different values to another table (like a left join with condition)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-a-field-with-different-values-to-another-table/m-p/693919#M211604</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I show you what I want to do. I have to tables: have1 and have2 and I want to have the table "want". If date of have2 is between start_date and end_date I want to copy this field&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you help me with this?&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
informat Start_Date End_Date ddmmyy10.;
format Start_Date End_Date ddmmyy10.;
input id  Start_Date  End_Date;
datalines;
10 08/02/2020 07/03/2020
10 02/10/2020 18/10/2020
;;;;
run;
data have2;
infile datalines delimiter=',';
informat Date ddmmyy10.;
format Date  ddmmyy10.;
input id  Date  ;
datalines;
10,01/01/20
10,15/02/20
10,01/04/20
10,05/05/20
10,05/10/20
;;;;
run;
data want;
infile datalines delimiter=',';
informat Date Start_Date End_Date ddmmyy10.;
format Date Start_Date End_Date ddmmyy10.;
input id  Date  Start_Date  End_Date;
datalines;
10,01/01/20,.,.
10,15/02/20,08/02/2020,07/03/2020
10,01/04/20,.,.
10,05/05/20,.,.
10,05/10/20,02/10/2020,18/10/2020
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2020 20:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-a-field-with-different-values-to-another-table/m-p/693919#M211604</guid>
      <dc:creator>t34</dc:creator>
      <dc:date>2020-10-23T20:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer a field with different values to another table (like a left join with condition)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-a-field-with-different-values-to-another-table/m-p/693943#M211606</link>
      <description>&lt;P&gt;OK, so your results should look like this, yes?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1603492694729.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51020iAAB726D5DFCB6676/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1603492694729.png" alt="jimbarbour_0-1603492694729.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There might be multiple ways to do this, but I would use an array to hold the start and end dates and then index through the array looking for dates that fell between each start and end date range.&amp;nbsp; Sample code is below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have1;
	LENGTH	ID	3;
	informat Start_Date End_Date ddmmyy10.;
	format Start_Date End_Date ddmmyy10.;
	input id  Start_Date  End_Date;

	CALL	SYMPUTX	('Nbr_Of_Dates', _N_, 'G');
datalines;
10 08/02/2020 07/03/2020
10 02/10/2020 18/10/2020
;;;;
RUN;

**------------------------------------------------------------------------------**;

DATA have2;
	LENGTH	ID	3;
	infile datalines dsd delimiter=',';
	informat Date ddmmyy10.;
	format Date  ddmmyy10.;
	input id  Date  ;
datalines;
10,01/01/20
10,15/02/20
10,01/04/20
10,05/05/20
10,05/10/20
;;;;
RUN;

**------------------------------------------------------------------------------**;

DATA want;
	DROP	_:;

	FORMAT	ID	Date;

	IF	_N_									=	1		THEN
		DO;
			DO	_i							=	1	TO	&amp;amp;Nbr_Of_Dates;
				SET	Have1	(RENAME=(ID		=	_ID));
				ARRAY	IDs						[&amp;amp;Nbr_Of_Dates]	_TEMPORARY_;
				ARRAY	Starts					[&amp;amp;Nbr_Of_Dates]	_TEMPORARY_;
				ARRAY	Ends					[&amp;amp;Nbr_Of_Dates]	_TEMPORARY_;
				IDs[_i]						=	_ID;
				Starts[_i]					=	Start_Date;
				Ends[_i]					=	End_Date;
*				PUTLOG	"NOTE:  "  _i=  Starts[_i]=  Ends[_i]=;
			END;
		END;

	SET	Have2;

	_Match									=	0;

	DO	_i									=	1	TO	&amp;amp;Nbr_Of_Dates;
		IF	ID								=	IDs[_i]		THEN
			DO;
				IF	Starts[_i]	&amp;lt;	Date	&amp;lt;	Ends[_i]	THEN
					DO;
						_Match				=	1;
						Start_Date			=	Starts[_i];
						End_Date			=	Ends[_i];
						OUTPUT;
					END;
				ELSE
					DO;
					END;
			END;
		ELSE
			DO;
			END;
	END;

	IF	NOT	_Match	THEN
		DO;
			CALL	MISSING(Start_Date, End_Date);
			OUTPUT;
		END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2020 22:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-a-field-with-different-values-to-another-table/m-p/693943#M211606</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-23T22:39:52Z</dc:date>
    </item>
  </channel>
</rss>

