<?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 Move values of a variable when missing values of another variable(s) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-when-missing-values-of-another/m-p/952168#M42799</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID :$20. Admission :date09. Discharge :date09. Variable1 Variable2 Index; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1  0  0
0001 21FEB2015 31DEC2015 0  1  1
0001 21FEB2015 31DEC2015 .  .  1
0001 01JAN2019 31DEC2019 0  1  0
0002 01JAN2015 31DEC2015 1  0  0
0002 01JAN2019 31OCT2019 1  0  0
0002 01JAN2019 31OCT2019 .  .  1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get the following for repeated (only!) dates?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have1;
  input ID :$20. Admission :date09. Discharge :date09. Variable1 Variable2 Index; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1  0  0
0001 21FEB2015 31DEC2015 0  1  1
0001 21FEB2015 31DEC2015 .  .  .
0001 01JAN2019 31DEC2019 0  1  0
0002 01JAN2015 31DEC2015 1  0  0
0002 01JAN2019 31OCT2019 1  0  1
0002 01JAN2019 31OCT2019 .  .  .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words if Index = 1 where Variable1 and Variable2 = . then the value of Index should be moved where not missing(Variable1, Variable2). If already there (e.g., ID = 0001 at 21FEB2015) then it should be set to missing when Variable1 and Variable2 = .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Fri, 29 Nov 2024 12:52:43 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2024-11-29T12:52:43Z</dc:date>
    <item>
      <title>Move values of a variable when missing values of another variable(s)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-when-missing-values-of-another/m-p/952168#M42799</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID :$20. Admission :date09. Discharge :date09. Variable1 Variable2 Index; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1  0  0
0001 21FEB2015 31DEC2015 0  1  1
0001 21FEB2015 31DEC2015 .  .  1
0001 01JAN2019 31DEC2019 0  1  0
0002 01JAN2015 31DEC2015 1  0  0
0002 01JAN2019 31OCT2019 1  0  0
0002 01JAN2019 31OCT2019 .  .  1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get the following for repeated (only!) dates?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have1;
  input ID :$20. Admission :date09. Discharge :date09. Variable1 Variable2 Index; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1  0  0
0001 21FEB2015 31DEC2015 0  1  1
0001 21FEB2015 31DEC2015 .  .  .
0001 01JAN2019 31DEC2019 0  1  0
0002 01JAN2015 31DEC2015 1  0  0
0002 01JAN2019 31OCT2019 1  0  1
0002 01JAN2019 31OCT2019 .  .  .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words if Index = 1 where Variable1 and Variable2 = . then the value of Index should be moved where not missing(Variable1, Variable2). If already there (e.g., ID = 0001 at 21FEB2015) then it should be set to missing when Variable1 and Variable2 = .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2024 12:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-when-missing-values-of-another/m-p/952168#M42799</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-11-29T12:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of a variable when missing values of another variable(s)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-when-missing-values-of-another/m-p/952182#M42800</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;, here's a quick solution:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create flags which capture the index for the duplicate dates which&amp;nbsp;have&amp;nbsp;&lt;SPAN&gt;Variable1=. and Variable2 =. and Index = 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_flags;
	set have;
	by id admission discharge;
	if variable1 =. and variable2 =. and index^=. then flag=index;
	if flag=1;
	keep id admission discharge flag;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; 2. Merge have_flags back in with the original dataset by id, admission and discharge dates. Using the logic you described, assign index=. or index=flag:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	merge have have_flags;
	by id admission discharge;
	if variable1=. and variable2=. and flag=1 then index=.;
	else if variable1^=. and variable2^=. and index=0 and flag^=. then index=flag;
	drop flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2024 16:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-when-missing-values-of-another/m-p/952182#M42800</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2024-11-29T16:43:57Z</dc:date>
    </item>
  </channel>
</rss>

