<?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 Copy values based on certain criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516809#M139620</link>
    <description>&lt;P&gt;Hi, there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am&amp;nbsp;curious how to achieve this in SAS. My data is sorted by id and date.&amp;nbsp;for id "a", if the days between date in row 3 and row 4 is equal to 3, then I want to copy var1 to var2. Otherwise, in case id"b", if the &lt;SPAN&gt;days&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;between date in row 3 and row 4 is not equal to 3, then leave it blank.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance!!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';			
Input ID$ date :ddmmyy10. var1 var2;
format date YYMMDDn8.; 
cards;
a,	01/01/2018,	.	,111,
a,	02/01/2018,	.	,111,
a,	03/01/2018,	.	,111,
a,	06/01/2018,	222	,.,
a,	07/01/2018,	222	,.,
b,	08/01/2018,	.	,111,
b,	09/01/2018,	.	,111,
b,	10/01/2018,	.	,111,
b,	11/01/2018,	222	,.,
b,	12/01/2018,	222	,.,
;			
run;

data want;
infile cards dlm=',';			
Input ID$ date :ddmmyy10. var1 var2;
format date YYMMDDn8.; 
cards;
a,	01/01/2018,	.	,111,
a,	02/01/2018,	.	,111,
a,	03/01/2018,	.	,111,
a,	06/01/2018,	222	,222,
a,	07/01/2018,	222	,.,
b,	08/01/2018,	.	,111,
b,	09/01/2018,	.	,111,
b,	10/01/2018,	.	,111,
b,	11/01/2018,	222	,.,
b,	12/01/2018,	222	,.,
;			
run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Nov 2018 17:36:32 GMT</pubDate>
    <dc:creator>lpy0521</dc:creator>
    <dc:date>2018-11-28T17:36:32Z</dc:date>
    <item>
      <title>Copy values based on certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516809#M139620</link>
      <description>&lt;P&gt;Hi, there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am&amp;nbsp;curious how to achieve this in SAS. My data is sorted by id and date.&amp;nbsp;for id "a", if the days between date in row 3 and row 4 is equal to 3, then I want to copy var1 to var2. Otherwise, in case id"b", if the &lt;SPAN&gt;days&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;between date in row 3 and row 4 is not equal to 3, then leave it blank.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance!!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';			
Input ID$ date :ddmmyy10. var1 var2;
format date YYMMDDn8.; 
cards;
a,	01/01/2018,	.	,111,
a,	02/01/2018,	.	,111,
a,	03/01/2018,	.	,111,
a,	06/01/2018,	222	,.,
a,	07/01/2018,	222	,.,
b,	08/01/2018,	.	,111,
b,	09/01/2018,	.	,111,
b,	10/01/2018,	.	,111,
b,	11/01/2018,	222	,.,
b,	12/01/2018,	222	,.,
;			
run;

data want;
infile cards dlm=',';			
Input ID$ date :ddmmyy10. var1 var2;
format date YYMMDDn8.; 
cards;
a,	01/01/2018,	.	,111,
a,	02/01/2018,	.	,111,
a,	03/01/2018,	.	,111,
a,	06/01/2018,	222	,222,
a,	07/01/2018,	222	,.,
b,	08/01/2018,	.	,111,
b,	09/01/2018,	.	,111,
b,	10/01/2018,	.	,111,
b,	11/01/2018,	222	,.,
b,	12/01/2018,	222	,.,
;			
run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 17:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516809#M139620</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-11-28T17:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Copy values based on certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516810#M139621</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
    by id;
	prev_date=lag(date);
	if date-prev_date=3 and not first.id then var2=var1;
    drop prev_date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 17:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516810#M139621</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-28T17:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Copy values based on certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516814#M139622</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';			
Input ID$ date :ddmmyy10. var1 var2;
format date YYMMDDn8.; 
cards;
a,	01/01/2018,	.	,111,
a,	02/01/2018,	.	,111,
a,	03/01/2018,	.	,111,
a,	06/01/2018,	222	,.,
a,	07/01/2018,	222	,.,
b,	08/01/2018,	.	,111,
b,	09/01/2018,	.	,111,
b,	10/01/2018,	.	,111,
b,	11/01/2018,	222	,.,
b,	12/01/2018,	222	,.,
;			
run;

data want;
do _n_=1 by 1 until(last.id);
set have;
by id;
if _n_=4 and date-lag(date)=3 then var2=var1;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 17:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-based-on-certain-criteria/m-p/516814#M139622</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-28T17:50:09Z</dc:date>
    </item>
  </channel>
</rss>

