<?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: Comparing values of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311574#M270726</link>
    <description>&lt;P&gt;You can add new variables to output just by naming it and assigning it a value,&lt;/P&gt;
&lt;P&gt;like in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test; 
     infile datalines;
     input var1  var2;
     &lt;STRONG&gt;new_var =&lt;/STRONG&gt; var1 + var2;
datalines;
10 5
20 3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; in this case new_var is initiated again and again in eatch iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; using &lt;STRONG&gt;retain&lt;/STRONG&gt;&amp;nbsp; enables keep value through iterations, without to be initiated at new input comming.&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2016 01:04:20 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-11-15T01:04:20Z</dc:date>
    <item>
      <title>Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311503#M270720</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to compare the valus of a variable to understrand at what points thers is a significant change.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="0"&gt;&lt;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;gt;1.7*SRAD(i) &amp;nbsp;&lt;/SPAN&gt;then &amp;nbsp;x=1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It'd be appracited if you let me know how I can perform this comparison in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 20:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311503#M270720</guid>
      <dc:creator>Palang</dc:creator>
      <dc:date>2016-11-14T20:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311508#M270721</link>
      <description>&lt;P&gt;Are you trying to look forward or look back? Where do you want that result to go and does it matter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - looking back is easier than looking forward in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post what you would expect as output to help clarify your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 20:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311508#M270721</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-14T20:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311513#M270722</link>
      <description>&lt;P&gt;Thank you for the response. I got a time series dataset with 5 min resolution, and wanna spot the points at which solar radiation is suddenly decreased/increased by about %70. To do so, I want to compare the solar radiation quantities consecutively to spot the points of interest, and delete the rows at which this sudden increase/decrease doesn't happen. I think the code should look forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comparing the rows like this and set new variable "x" to 1 if the if statement is satisfied, o.w. x=0. Then, I can delete the rows with x=0.&lt;/P&gt;&lt;P&gt;if SRAD(i+1)&amp;lt;0.3*SRAD(i) then x=1;&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>Mon, 14 Nov 2016 20:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311513#M270722</guid>
      <dc:creator>Palang</dc:creator>
      <dc:date>2016-11-14T20:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311517#M270723</link>
      <description>&lt;P&gt;Try next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; retain prev_srad;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if _N_=1 then prev_srad = srad;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; relation = &amp;nbsp;srad / prev_srad ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if relation le 0.3 or relation ge 1.7 then x=1; else x=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;prev_srad = srad;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drop prev_srad;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 20:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311517#M270723</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-14T20:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311521#M270724</link>
      <description>&lt;P&gt;Thank you guys very much. The problem's been solved.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 20:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311521#M270724</guid>
      <dc:creator>Palang</dc:creator>
      <dc:date>2016-11-14T20:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311534#M270725</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you very much. The problem's been solved. Could you please shade some ligh on the prev_srad temporary variable and how does the itteration is performed?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you much.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 21:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311534#M270725</guid>
      <dc:creator>Palang</dc:creator>
      <dc:date>2016-11-14T21:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311574#M270726</link>
      <description>&lt;P&gt;You can add new variables to output just by naming it and assigning it a value,&lt;/P&gt;
&lt;P&gt;like in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test; 
     infile datalines;
     input var1  var2;
     &lt;STRONG&gt;new_var =&lt;/STRONG&gt; var1 + var2;
datalines;
10 5
20 3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; in this case new_var is initiated again and again in eatch iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; using &lt;STRONG&gt;retain&lt;/STRONG&gt;&amp;nbsp; enables keep value through iterations, without to be initiated at new input comming.&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 01:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311574#M270726</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-15T01:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311601#M270727</link>
      <description>&lt;P&gt;Thank you very much for the info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regareds,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 03:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/311601#M270727</guid>
      <dc:creator>Palang</dc:creator>
      <dc:date>2016-11-15T03:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/312119#M270728</link>
      <description>&lt;P&gt;Minor difference code using the LAG function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  relation =  srad / lag(srad) ;
  if relation le 0.3 or relation ge 1.7 then x=1; 
  else x=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;LAG(variablename) allows you to examine values of a variable on previous rows of a data set. Use Lag2 to look at the record 2 before the current, Lag3 the record 3 before the current and so on. There are some tricky elements so it is best not to use LAG, or the related function DIF, in conditional statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 21:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/312119#M270728</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T21:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/312133#M270729</link>
      <description>Thank you very much.</description>
      <pubDate>Wed, 16 Nov 2016 22:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-a-variable/m-p/312133#M270729</guid>
      <dc:creator>Palang</dc:creator>
      <dc:date>2016-11-16T22:07:40Z</dc:date>
    </item>
  </channel>
</rss>

