<?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 where values of another variable appear in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947025#M42521</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 DB;
  input ID :$20. Event Index;
cards;
0001 1  0
0001 0  1
0002 1  1
0002 0  0
0003 1  0
0003 0  2
0003 0  0
0003 0  0
0003 0  0
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get 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 DB1;
  input ID :$20. Event Index;
cards;
0001 1  1
0001 0  0
0002 1  1
0002 0  0
0003 1  2
0003 0  0
0003 0  0
0003 0  0
0003 0  0
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words the value of Index should be moved where event = 1 when it is already not there. Only moved. No other calculation is required.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 16:52:59 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2024-10-10T16:52:59Z</dc:date>
    <item>
      <title>Move values of a variable where values of another variable appear</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947025#M42521</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 DB;
  input ID :$20. Event Index;
cards;
0001 1  0
0001 0  1
0002 1  1
0002 0  0
0003 1  0
0003 0  2
0003 0  0
0003 0  0
0003 0  0
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get 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 DB1;
  input ID :$20. Event Index;
cards;
0001 1  1
0001 0  0
0002 1  1
0002 0  0
0003 1  2
0003 0  0
0003 0  0
0003 0  0
0003 0  0
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words the value of Index should be moved where event = 1 when it is already not there. Only moved. No other calculation is required.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 16:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947025#M42521</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-10-10T16:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of a variable where values of another variable appear</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947034#M42522</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 some code that will get the job done but I should mention it's convoluted and makes a few assumptions which may or may not work in all situations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data db_temp;
	retain max_index;
	set db;
	by id;
	
	if first.id then max_index=0;
	max_index=max(max_index,index);
	if last.id;
	keep id max_index;
run;

data db1;
	merge db db_temp;
	by id;
	if event=1 then index=max_index;
	else if index=max_index then index=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy to iterate if you can provide more information about whether each ID will have at least one observation where event=1, whether max(index) is what we're looking for, ...&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 17:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947034#M42522</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2024-10-10T17:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of a variable where values of another variable appear</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947044#M42526</link>
      <description>&lt;P&gt;Your need to explain more about the meaning of these variables.&amp;nbsp; And why you want to "move" the values.&amp;nbsp; How did they get in the wrong place to begin with?&amp;nbsp; Can you instead fix the process that put them in the wrong place?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does each ID only have one observation where EVENT=1?&lt;/P&gt;
&lt;P&gt;Is it always the first observation like it is in your examples?&lt;/P&gt;
&lt;P&gt;If so then I would recommend just merging the data with itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Event Index;
cards;
0001 1  0
0001 0  1
0002 1  1
0002 0  0
0003 1  0
0003 0  2
0003 0  0
0003 0  0
0003 0  0
;

data want;
  merge db(drop=index) db(keep=id index where=(index));
  by id;
  if not first.id then index=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 18:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947044#M42526</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-10T18:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of a variable where values of another variable appear</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947045#M42527</link>
      <description>Hi Tom. The values (of "Index" variable) are not in the desired order because two tables were merged and the one containing the values not in the desired order was used for other calculation for which that order had to be maintained.&lt;BR /&gt;Does each ID only have one observation where EVENT=1? yes absolutely.&lt;BR /&gt;&lt;BR /&gt;Is it always the first observation like it is in your examples? Yes it is absolutely.</description>
      <pubDate>Thu, 10 Oct 2024 18:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947045#M42527</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-10-10T18:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of a variable where values of another variable appear</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947075#M42529</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Event Index;
cards;
0001 1  0
0001 0  1
0002 1  1
0002 0  0
0003 1  0
0003 0  2
0003 0  0
0003 0  0
0003 0  0
;

proc sql;
create table want as
select ID,Event,case when Event then max(Index) else 0 end as Index
 from DB 
  group by ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2024 01:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-a-variable-where-values-of-another-variable/m-p/947075#M42529</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-11T01:19:28Z</dc:date>
    </item>
  </channel>
</rss>

