<?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 variables where a variable takes a value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954160#M42890</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have this highly sparse dataset:&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. Index Variable1  Variable2  Variable3 Variable4;
cards;
0001 1  .  1  .   .
0001 0  1  .  .   1
0002 1  1  .  .   1
0002 0  .  1  .   .
0003 1  .  .  .   .
0003 0  2  .  4   .
0003 0  .  3  .   .
0003 0  .  .  .   .
0003 0  .  .  .   8  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to move all values of Variable: where Index = 1 to have the following?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Index Variable1  Variable2  Variable3 Variable4;
cards;
0001 1  1  1  .   1
0001 0  .  .  .   .
0002 1  1  1  .   1
0002 0  .  .  .   .
0003 1  2  3  4   8
0003 0  .  .  .   .
0003 0  .  .  .   .
0003 0  .  .  .   .
0003 0  .  .  .   .  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: no replicates are present by ID for each Variable:&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Thu, 19 Dec 2024 14:41:44 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2024-12-19T14:41:44Z</dc:date>
    <item>
      <title>Move values of variables where a variable takes a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954160#M42890</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have this highly sparse dataset:&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. Index Variable1  Variable2  Variable3 Variable4;
cards;
0001 1  .  1  .   .
0001 0  1  .  .   1
0002 1  1  .  .   1
0002 0  .  1  .   .
0003 1  .  .  .   .
0003 0  2  .  4   .
0003 0  .  3  .   .
0003 0  .  .  .   .
0003 0  .  .  .   8  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to move all values of Variable: where Index = 1 to have the following?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Index Variable1  Variable2  Variable3 Variable4;
cards;
0001 1  1  1  .   1
0001 0  .  .  .   .
0002 1  1  1  .   1
0002 0  .  .  .   .
0003 1  2  3  4   8
0003 0  .  .  .   .
0003 0  .  .  .   .
0003 0  .  .  .   .
0003 0  .  .  .   .  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: no replicates are present by ID for each Variable:&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 14:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954160#M42890</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-12-19T14:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of variables where a variable takes a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954162#M42891</link>
      <description>&lt;P&gt;Just collapse and then remerge.&amp;nbsp; If you only have one observation with INDEX=1 per ID value then using a conditional SET statement will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Index Variable1-Variable4;
cards;
0001 1  .  1  .   .
0001 0  1  .  .   1
0002 1  1  .  .   1
0002 0  .  1  .   .
0003 1  .  .  .   .
0003 0  2  .  4   .
0003 0  .  3  .   .
0003 0  .  .  .   .
0003 0  .  .  .   8
;

data final;
  update db(obs=0) db;
  by id;
  drop index;
run;

data want;
  set db (keep=id index) ;
  if index then set final ;
  else call missing(of variable1-variable4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Having to do things like this makes it seems that you have issues in your upstream processes.&amp;nbsp; How did you end up with such a messy dataset?&amp;nbsp; What are you going to do with the resulting dataset? It does not look that useful for analysis.&amp;nbsp; What value do all of those observations with only missing values add??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 14:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954162#M42891</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-19T14:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of variables where a variable takes a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954164#M42892</link>
      <description>&lt;P&gt;This is one way to accomplish your task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data DB; &lt;BR /&gt;input ID :$20. Index Variable1 Variable2 Variable3 Variable4; &lt;BR /&gt;cards; &lt;BR /&gt;0001 1 . 1 . . &lt;BR /&gt;0001 0 1 . . 1 &lt;BR /&gt;0002 1 1 . . 1 &lt;BR /&gt;0002 0 . 1 . . &lt;BR /&gt;0003 1 . . . . &lt;BR /&gt;0003 0 2 . 4 . &lt;BR /&gt;0003 0 . 3 . . &lt;BR /&gt;0003 0 . . . . &lt;BR /&gt;0003 0 . . . 8 &lt;BR /&gt;; &lt;BR /&gt;&lt;BR /&gt;proc sort out=newdb; &lt;BR /&gt;by descending id index; &lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;data new; &lt;BR /&gt;set newdb; &lt;BR /&gt;retain tvar1 tvar2 tvar3 tvar4; &lt;BR /&gt;array vars(*) variable1-variable4; &lt;BR /&gt;array tempvars(*) tvar1-tvar4; &lt;BR /&gt;by descending id index; &lt;BR /&gt;if index=0 then do; &lt;BR /&gt;do i= 1 to dim(vars); &lt;BR /&gt;if vars(i) ne . then tempvars(i)=vars(i); &lt;BR /&gt;vars(i)=.; &lt;BR /&gt;end; &lt;BR /&gt;end; &lt;BR /&gt;else if index=1 then do; &lt;BR /&gt;do i= 1 to dim(vars); &lt;BR /&gt;if vars(i)=. then vars(i)=tempvars(i); &lt;BR /&gt;end; &lt;BR /&gt;call missing(tvar1,tvar2,tvar3,tvar4); &lt;BR /&gt;end; &lt;BR /&gt;drop tvar: i; &lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;proc sort out=newdb; &lt;BR /&gt;by id descending index; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 14:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954164#M42892</guid>
      <dc:creator>russt_sas</dc:creator>
      <dc:date>2024-12-19T14:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of variables where a variable takes a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954167#M42893</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Having to do things like this makes it seems that you have issues in your upstream processes.&amp;nbsp; How did you end up with such a messy dataset?&amp;nbsp; What are you going to do with the resulting dataset? It does not look that useful for analysis.&amp;nbsp; What value do all of those observations with only missing values add??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suspect it may be related to the &lt;A href="https://communities.sas.com/t5/New-SAS-User/Fill-with-values-a-set-of-variables-to-reach-the-total/m-p/953701" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/Fill-with-values-a-set-of-variables-to-reach-the-total/m-p/953701&lt;/A&gt; bit where the "fill to value" was apparently to fix an incorrect count. Perhaps this data the index=0 with all the missing values are the "not an event" that the filled in values represented. I agree that this seems to represent a moderately flawed data structure at some point of the process. Look at &lt;A href="https://communities.sas.com/t5/New-SAS-User/From-long-format-to-short-data-format/td-p/953512" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/From-long-format-to-short-data-format/td-p/953512&lt;/A&gt; for where the Variable1-Variable4 may have come from as well.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 15:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954167#M42893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-19T15:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Move values of variables where a variable takes a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954172#M42895</link>
      <description>&lt;P&gt;Wouldn't it be simpler to just collapse to one observation per ID?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db ;
  by id;
  var index variable1-variable4 ;
  output out=want(drop=_type_ _freq_) max= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Dec 2024 15:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Move-values-of-variables-where-a-variable-takes-a-value/m-p/954172#M42895</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-19T15:37:21Z</dc:date>
    </item>
  </channel>
</rss>

