<?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 Retain in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556360#M154992</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I would like to retain the value of column Z for each customer.&lt;/P&gt;
&lt;P&gt;The input data set has&amp;nbsp; 2 columns: ID ,Z&lt;/P&gt;
&lt;P&gt;1 10&lt;BR /&gt;1 15&lt;BR /&gt;1 20&lt;BR /&gt;2 50&lt;BR /&gt;2 45&lt;BR /&gt;2 55&lt;BR /&gt;3 40&lt;BR /&gt;3 42&lt;BR /&gt;3 38&lt;/P&gt;
&lt;P&gt;The desired data set will have the following columns ID,Z,First_Z with following values:&lt;/P&gt;
&lt;P&gt;1 10 10&lt;BR /&gt;1 15 10&lt;BR /&gt;1 20 10&lt;BR /&gt;2 50 50&lt;BR /&gt;2 45 50&lt;BR /&gt;2 55 50&lt;BR /&gt;3 40 40&lt;BR /&gt;3 42 40&lt;BR /&gt;3 38 40&lt;/P&gt;
&lt;P&gt;What is the way to do it using Retain statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID Z;
cards;
1 10
1 15
1 20
2 50
2 45
2 55
3 40
3 42
3 38
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 06 May 2019 08:09:57 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-05-06T08:09:57Z</dc:date>
    <item>
      <title>Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556360#M154992</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I would like to retain the value of column Z for each customer.&lt;/P&gt;
&lt;P&gt;The input data set has&amp;nbsp; 2 columns: ID ,Z&lt;/P&gt;
&lt;P&gt;1 10&lt;BR /&gt;1 15&lt;BR /&gt;1 20&lt;BR /&gt;2 50&lt;BR /&gt;2 45&lt;BR /&gt;2 55&lt;BR /&gt;3 40&lt;BR /&gt;3 42&lt;BR /&gt;3 38&lt;/P&gt;
&lt;P&gt;The desired data set will have the following columns ID,Z,First_Z with following values:&lt;/P&gt;
&lt;P&gt;1 10 10&lt;BR /&gt;1 15 10&lt;BR /&gt;1 20 10&lt;BR /&gt;2 50 50&lt;BR /&gt;2 45 50&lt;BR /&gt;2 55 50&lt;BR /&gt;3 40 40&lt;BR /&gt;3 42 40&lt;BR /&gt;3 38 40&lt;/P&gt;
&lt;P&gt;What is the way to do it using Retain statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID Z;
cards;
1 10
1 15
1 20
2 50
2 45
2 55
3 40
3 42
3 38
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 08:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556360#M154992</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-05-06T08:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556365#M154993</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=tbl;
by id;
run;

data want;
set tbl;
by id;
retain newvar;
if first.id then newvar=z;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 08:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556365#M154993</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-06T08:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556368#M154994</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID Z;
cards;
1 10
1 15
1 20
2 50
2 45
2 55
3 40
3 42
3 38
;
run;

data want;
   set tbl;
   by ID;
   if first.ID then First_Z=Z;
   retain First_Z;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 08:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/556368#M154994</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-06T08:59:15Z</dc:date>
    </item>
  </channel>
</rss>

