<?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: assigning a value to a variable through a condition. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336385#M76248</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I didn't make my question clear, please see the attachement for more details. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to compare the C_ID with C_IDN and if the CEDT and PDT the same than create a new varaible named NPN with the PN's value and if the PDT is less than the TDTN than I want the previous PN value for the NPN vaule.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2017 00:01:36 GMT</pubDate>
    <dc:creator>BonnaryW</dc:creator>
    <dc:date>2017-02-28T00:01:36Z</dc:date>
    <item>
      <title>assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336377#M76244</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone can help me with my code. I need to place an existing value to a new variable, instead it's giving me a zero value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; ALLC; SET ALLB;&lt;/P&gt;&lt;P&gt;LENGTH NPN $&lt;STRONG&gt;5&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;IF (C_ID=C_IDN) AND (TDTN &amp;gt; PDT) THEN NPN=FIRST.PN;&lt;/P&gt;&lt;P&gt;ELSE NPN = PN;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;PRINT&lt;/STRONG&gt; N; ID C_ID; VAR CPRENDINGDT PDT TDTN NPN PN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Result:&amp;nbsp; Pelase see attachement.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 23:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336377#M76244</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-27T23:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336378#M76245</link>
      <description>&lt;P&gt;You can't use first.pn without including a&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by pn;&lt;/P&gt;
&lt;P&gt;statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 23:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336378#M76245</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-27T23:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336379#M76246</link>
      <description>&lt;P&gt;First.PN will always be 1 or 0, as it's an indicator if a record is&amp;nbsp;the first record or not. It does not hold the value of the first value of PN which is what I think you're looking for, see the code below. I had to add, BY and RETAIN statements and modified the code to keep the first variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please clarify your question by describing what you want rather than code that doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, post sample data as text directly in the forum as mnay users won't work with xlsx or docx files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;DATA ALLC; SET ALLB;
LENGTH NPN $5;
by PN;
Retain First_PN;

if first.PN then First_PN= PN;

IF (C_ID=C_IDN) AND (TDTN &amp;gt; PDT) THEN NPN=First_PN;
ELSE NPN = PN;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 23:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336379#M76246</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-27T23:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336382#M76247</link>
      <description>&lt;P&gt;Are pdt and tdtn sas dates or just character fields containing date looking information? If they're character fields, in addition to the first. problem, your logic won't work as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 23:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336382#M76247</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-27T23:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336385#M76248</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I didn't make my question clear, please see the attachement for more details. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to compare the C_ID with C_IDN and if the CEDT and PDT the same than create a new varaible named NPN with the PN's value and if the PDT is less than the TDTN than I want the previous PN value for the NPN vaule.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336385#M76248</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-28T00:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336386#M76249</link>
      <description>&lt;P&gt;You didn't answer my question: are the dates character fields or SAS dates?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336386#M76249</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-28T00:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336387#M76250</link>
      <description>I am sorry Art, The date is SAS dateformat as date9. Thank you.&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336387#M76250</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-28T00:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336388#M76251</link>
      <description>&lt;P&gt;OK. But your question still isn't clear. You said:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need to compare the C_ID with C_IDN and if the CEDT and PDT the same than create a new varaible named NPN with the PN's value and if the PDT is less than the TDTN than I want the previous PN value for the NPN vaule.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You mention comparing&amp;nbsp;C_ID with C_IDN, but didn't say anything about what if they are equal or unequal. Are you saying that if&amp;nbsp;C_ID and&amp;nbsp;C_IDN are the same, and if CEDT and PDT are the same, then create the new variable equal to the PN value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you want to do the pdt less than computation ONLY if the condition in the last paragraph isn't met?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Art, CEO, AnalystFinder.com&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336388#M76251</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-28T00:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336389#M76252</link>
      <description>&lt;P&gt;Did you try the code? What part of it was incorrect?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336389#M76252</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-28T00:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336392#M76253</link>
      <description>Thank you and yes, it didn't give me the previous value, it give me the current value. At least it didn't give me the zero value.&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336392#M76253</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-28T00:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336396#M76256</link>
      <description>&lt;P&gt;When you say previous value, are you referring to the previous value as the previous row, or the previous value as the previous value in the series.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Small sample datasets that show input and output goes a long way..&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336396#M76256</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-28T00:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336397#M76257</link>
      <description>Thank you Art for your response.&lt;BR /&gt;&lt;BR /&gt;I need to compare the C_ID with C_IDN and if they are equal then if the CEDT and PDT the same than create a new variable named NPN with the PN's value and if the PDT is less than the TDTN than I want the previous PN value for the NPN value.&lt;BR /&gt;&lt;BR /&gt;YES, please. You mention comparing C_ID with C_IDN, but didn't say anything about what if they are equal or unequal. Are you saying that if C_ID and C_IDN are the same, and if CEDT and PDT are the same, then create the new variable equal to the PN value.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Do you want to do the pdt less than computation ONLY if the condition in the last paragraph isn't met? If the PDT less than the TDTN and if C_ID and C_IDN are the same, and if CEDT and PDT are the same, then create the new variable equal to the previous PN value.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you Art.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336397#M76257</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-28T00:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a value to a variable through a condition.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336399#M76258</link>
      <description>Yes. Thank you so much Reeza.&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Feb 2017 00:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-value-to-a-variable-through-a-condition/m-p/336399#M76258</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-28T00:46:19Z</dc:date>
    </item>
  </channel>
</rss>

