<?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: spreading values across observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515904#M139286</link>
    <description>&lt;P&gt;You require was&lt;/P&gt;
&lt;PRE&gt;Then I want to retain the value of  InBaseMon (from first row of customer to other rows of customer)&lt;/PRE&gt;
&lt;P&gt;RETAIN will &lt;STRONG&gt;hold the value through observations&lt;/STRONG&gt; until it is changed by the code.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Nov 2018 07:00:31 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-11-26T07:00:31Z</dc:date>
    <item>
      <title>spreading values across observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515899#M139281</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In following raw data there are 3 fields: ID ,month, weight.&lt;/P&gt;
&lt;P&gt;I want to check IF customer was exist in base month (1801) and give him value 1 if yes and 0 if no.&lt;/P&gt;
&lt;P&gt;I want that value 1 or 0 will appear in all rows for the customer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The task is to create a new column &amp;nbsp;"InBaseMon" &amp;nbsp;.&lt;/P&gt;
&lt;P&gt;IF first raw of customer has month=1801 &amp;nbsp;then &amp;nbsp;&lt;SPAN&gt;InBaseMon=1.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IF first raw of customer has month=1801 &amp;nbsp;then &amp;nbsp;InBaseMon=0.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then I want to retain the value of &amp;nbsp;InBaseMon (from first row of customer to other rows of customer)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The expected values for new varaible "InBaseMon"&amp;nbsp;&amp;nbsp;for ID=1 &amp;nbsp;are: &amp;nbsp; 1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The expected value&lt;/SPAN&gt;&lt;SPAN&gt;s for new varaible "&lt;/SPAN&gt;&lt;SPAN&gt;InBaseMon"&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;for ID=2 &amp;nbsp;are: &amp;nbsp; 1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The expected value&lt;/SPAN&gt;&lt;SPAN&gt;s for new varaible "&lt;/SPAN&gt;&lt;SPAN&gt;InBaseMon"&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;for ID=3 &amp;nbsp;are: &amp;nbsp;0 &amp;nbsp;0&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data rawData;
Input ID month weight;
cards;
1 1801 100
1 1802 90
1 1803 85
2 1801 90
2 1802 94
2 1803 93
3 1802 78
3 1803 80
;
run;

Data tbl1;
set rawData;
by ID;
IF (first.ID AND month=1801) then InBaseMon=1; 
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 06:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515899#M139281</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-11-26T06:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: spreading values across observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515901#M139283</link>
      <description>&lt;P&gt;I found solution&lt;/P&gt;
&lt;P&gt;May anyone explain the code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
set rawData;
by ID;
retain  &lt;SPAN&gt;InBaseMon&lt;/SPAN&gt; ;
if first.ID then do;
	&lt;SPAN&gt;InBaseMon&lt;/SPAN&gt;=0;	
	if month eq 1801 then &lt;SPAN&gt;InBaseMon&lt;/SPAN&gt;=1;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Nov 2018 07:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515901#M139283</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-11-26T07:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: spreading values across observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515903#M139285</link>
      <description>&lt;P&gt;/*Way2*/&lt;BR /&gt;Data tbl1;&lt;BR /&gt;set rawData;&lt;BR /&gt;by ID;&lt;BR /&gt;retain &lt;SPAN&gt;InBaseMon&lt;/SPAN&gt;;&lt;BR /&gt;if first.ID and month eq 1801 then &lt;SPAN&gt;InBaseMon&lt;/SPAN&gt;=1;&lt;BR /&gt;if first.ID and month ne 1801 then &lt;SPAN&gt;InBaseMon&lt;/SPAN&gt;=0;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 07:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515903#M139285</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-11-26T07:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: spreading values across observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515904#M139286</link>
      <description>&lt;P&gt;You require was&lt;/P&gt;
&lt;PRE&gt;Then I want to retain the value of  InBaseMon (from first row of customer to other rows of customer)&lt;/PRE&gt;
&lt;P&gt;RETAIN will &lt;STRONG&gt;hold the value through observations&lt;/STRONG&gt; until it is changed by the code.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 07:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515904#M139286</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-26T07:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: spreading values across observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515913#M139288</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I found solution&lt;/P&gt;
&lt;P&gt;May anyone explain the code?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
set rawData;
by ID;
retain  InBaseMon ; * do not set InBaseMon to missing at the start of a data step iteration;
if first.ID then do; * do this in the first row for every id group;
	InBaseMon=0;	
	if month eq 1801 then InBaseMon=1; * set inbasemon conditionally;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The most compact method to set your variable is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tbl1;
set rawdata;
by id;
retain inbasemon;
if first.id then inbasemon = ifn(month eq 1801,1,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Nov 2018 08:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/spreading-values-across-observations/m-p/515913#M139288</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-26T08:34:06Z</dc:date>
    </item>
  </channel>
</rss>

