<?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 Re: Repeat the value in a varaible across the rows. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246900#M268605</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This selects all the data, then left joins the max value per ID group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  A.*,
            B.MAX_VALUE
  from    HAVE A
  left join (select ID,
               max(VAR1) as MAX_VALUE 
               from HAVE 
               group by ID) B
  on       A.ID=B.ID;
quit;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jan 2016 15:09:52 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-01-29T15:09:52Z</dc:date>
    <item>
      <title>Repeat the value in a varaible across the rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246898#M268604</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fairly new to SAS and would really appreciate help with a particular problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;have a&amp;nbsp;dataset comprising multiple rows per person. &amp;nbsp;For each person, I would like to&amp;nbsp;transfer the &lt;STRONG&gt;maximum&amp;nbsp;&lt;/STRONG&gt;value&amp;nbsp;from&amp;nbsp;variable 1 (var1)&amp;nbsp;onto all the other rows for that person&amp;nbsp;and&amp;nbsp;into&amp;nbsp;a new variable (newvar).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp; Var1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;4&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;6&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;....would become.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp; Var1 &amp;nbsp; Newvar&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 15:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246898#M268604</guid>
      <dc:creator>tim_bradshaw</dc:creator>
      <dc:date>2016-01-29T15:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the value in a varaible across the rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246900#M268605</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This selects all the data, then left joins the max value per ID group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  A.*,
            B.MAX_VALUE
  from    HAVE A
  left join (select ID,
               max(VAR1) as MAX_VALUE 
               from HAVE 
               group by ID) B
  on       A.ID=B.ID;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2016 15:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246900#M268605</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-29T15:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the value in a varaible across the rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246901#M268606</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id descending var1;
run;
data want;
set have;
retain newvar;
by id descending var1;
if first.id then do;
newvar=var1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2016 15:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246901#M268606</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-29T15:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the value in a varaible across the rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246902#M268607</link>
      <description>&lt;P&gt;This is easy to do in PROC SQL because SAS will automatically remerge summary statistics for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
&amp;nbsp; &amp;nbsp;create table want as
&amp;nbsp; &amp;nbsp; &amp;nbsp;select *,max(var1) as newvar
&amp;nbsp; &amp;nbsp; &amp;nbsp;from have
&amp;nbsp; &amp;nbsp; &amp;nbsp;group by id
&amp;nbsp; &amp;nbsp;;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could do it in a data step using a technique known as DOW loops. The data must be sorted by ID .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  do until (last.id);
     set have;
     by id;
     newvar=max(newvar,var1);
  end;
  do until (last.id);
     set have;
     by id;
     output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 15:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246902#M268607</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-29T15:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the value in a varaible across the rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246908#M268608</link>
      <description>&lt;P&gt;Thank you so much for your solutions.&amp;nbsp;Your experise are&amp;nbsp;much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I meant to say that I have hundreds&amp;nbsp;of millions of observations so an efficient command will be the most useful. &amp;nbsp;I will try these and see....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 15:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246908#M268608</guid>
      <dc:creator>tim_bradshaw</dc:creator>
      <dc:date>2016-01-29T15:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the value in a varaible across the rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246911#M268609</link>
      <description>&lt;P&gt;If you have hundreds of millions of&amp;nbsp;observations then perhaps you should be thinking about big picture. &amp;nbsp;It will take a long time to read every observation find the max and write out all the data again with max attached. Then what? Will you read all hundreds of millions back in again to do what? &amp;nbsp;Programs that are adequate for most applications with thousand of observations may not be adequate when you have hundreds of millions of observations.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 15:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-value-in-a-varaible-across-the-rows/m-p/246911#M268609</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-01-29T15:35:14Z</dc:date>
    </item>
  </channel>
</rss>

