<?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: Value of variable depending on one entry of the data table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467675#M119412</link>
    <description>Thank you very much, Ksharp! Best regards, Leo</description>
    <pubDate>Tue, 05 Jun 2018 14:23:19 GMT</pubDate>
    <dc:creator>LeoBrunner</dc:creator>
    <dc:date>2018-06-05T14:23:19Z</dc:date>
    <item>
      <title>Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467253#M119274</link>
      <description>&lt;P&gt;Dear SAS-Community&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm&amp;nbsp;failing with a problem that actually sounds not very complicated:&lt;/P&gt;&lt;P&gt;I have a data table of the form as I've attached. For the case that you cannot open it, it looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code&amp;nbsp; &amp;nbsp; year&amp;nbsp; &amp;nbsp; &amp;nbsp;value&lt;/P&gt;&lt;P&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015&amp;nbsp; &amp;nbsp; 375&lt;/P&gt;&lt;P&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2016&amp;nbsp; &amp;nbsp; 640&lt;/P&gt;&lt;P&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2017&amp;nbsp; &amp;nbsp; 710&lt;/P&gt;&lt;P&gt;20&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;20&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015&amp;nbsp; &amp;nbsp; 125&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;20&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2016&amp;nbsp; &amp;nbsp; 950&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;20&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I like to do is the following: If the value of the line with code = 20 and year = 2017 is zero (as in my example), then I like to set the values of code 20 (only code 20!) for all years to zero. In my example this would mean that instead of the values 125 and 950 there should be written zero.&lt;/P&gt;&lt;P&gt;I'm very grateful for every help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards, Leo&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 20:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467253#M119274</guid>
      <dc:creator>LeoBrunner</dc:creator>
      <dc:date>2018-06-03T20:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467255#M119275</link>
      <description>&lt;P&gt;Since 2017 is the largest value sort it descending.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then 2017 will be the first value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by code descending year;
run;

data want;
set have;
retain flag;

if first.code and year=2017 and value=0 then flag=1;
else if first.code and year=2017 and value ne  0 then flag=0;

if flag=1 then value=0;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jun 2018 20:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467255#M119275</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-03T20:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467267#M119279</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Code    year     value ;
cards;
10        2015    375
10        2016    640
10        2017    710
20        2014        0
20        2015    125
20        2016    950
20        2017        0
;

proc sql;
create table want as
select code,year ,abs(max(value = 0 and year=2017)-1)*value as value
from have
group by code
order code,year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jun 2018 22:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467267#M119279</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-03T22:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467270#M119280</link>
      <description>&lt;P&gt;To me, this would be the most intuitive approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have (where=(year=2017 and code=20));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if value=0 then reset=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;retain reset;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if code=20 and reset=1 then value=0;&lt;/P&gt;
&lt;P&gt;drop reset;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that you always have one observation where YEAR is 2017 and CODE is 20.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 22:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467270#M119280</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-03T22:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467303#M119285</link>
      <description>Please check below code.&lt;BR /&gt;&lt;BR /&gt;DATA TEMP;&lt;BR /&gt;INPUT Code year value;&lt;BR /&gt;CARDS;&lt;BR /&gt;10 2015 375&lt;BR /&gt;10 2016 640&lt;BR /&gt;10 2017 710&lt;BR /&gt;20 2014 0&lt;BR /&gt;20 2015 125&lt;BR /&gt;20 2016 950&lt;BR /&gt;20 2017 0&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=TEMP;&lt;BR /&gt;TITLE 'Source Table';&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE TEMP1 AS&lt;BR /&gt;SELECT&lt;BR /&gt;Code,&lt;BR /&gt;Year,&lt;BR /&gt;MIN(value) as Min_Val,&lt;BR /&gt;CASE&lt;BR /&gt;WHEN calculated Min_Val=0 THEN 0&lt;BR /&gt;ELSE value&lt;BR /&gt;END as Final_Value&lt;BR /&gt;FROM&lt;BR /&gt;TEMP&lt;BR /&gt;GROUP BY&lt;BR /&gt;Code&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;&lt;BR /&gt;DATA TEMP;&lt;BR /&gt;SET TEMP1;&lt;BR /&gt;RENAME Final_value=Value;&lt;BR /&gt;DROP Min_Val;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=TEMP;&lt;BR /&gt;TITLE 'Final Table';&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Jun 2018 06:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467303#M119285</guid>
      <dc:creator>mahesh146</dc:creator>
      <dc:date>2018-06-04T06:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467387#M119309</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Code    year     value ;
cards;
10        2015    375
10        2016    640
10        2017    710
20        2014        0
20        2015    125
20        2016    950
20        2017        0
;

data want;
 do until(last.code);
   set have;
   by code;
   if year=2017 and value=0 then yes=1;
 end;
 do until(last.code);
   set have;
   by code;
   if yes then value=0;
   output;
 end;
 drop yes;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Jun 2018 13:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467387#M119309</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-04T13:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467670#M119408</link>
      <description>&lt;P&gt;Thank you very much, Reeza!&lt;/P&gt;&lt;P&gt;Best regards, Leo&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jun 2018 14:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467670#M119408</guid>
      <dc:creator>LeoBrunner</dc:creator>
      <dc:date>2018-06-05T14:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467671#M119409</link>
      <description>Thank you very much novinosrin! Best regards, Leo</description>
      <pubDate>Tue, 05 Jun 2018 14:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467671#M119409</guid>
      <dc:creator>LeoBrunner</dc:creator>
      <dc:date>2018-06-05T14:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467673#M119410</link>
      <description>Thank you very much, Astounding! Best regards, Leo</description>
      <pubDate>Tue, 05 Jun 2018 14:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467673#M119410</guid>
      <dc:creator>LeoBrunner</dc:creator>
      <dc:date>2018-06-05T14:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467674#M119411</link>
      <description>Thank you very much, mahesh! Best regards, Leo</description>
      <pubDate>Tue, 05 Jun 2018 14:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467674#M119411</guid>
      <dc:creator>LeoBrunner</dc:creator>
      <dc:date>2018-06-05T14:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Value of variable depending on one entry of the data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467675#M119412</link>
      <description>Thank you very much, Ksharp! Best regards, Leo</description>
      <pubDate>Tue, 05 Jun 2018 14:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Value-of-variable-depending-on-one-entry-of-the-data-table/m-p/467675#M119412</guid>
      <dc:creator>LeoBrunner</dc:creator>
      <dc:date>2018-06-05T14:23:19Z</dc:date>
    </item>
  </channel>
</rss>

