<?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: Help with a if then statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-a-if-then-statement/m-p/76455#M22173</link>
    <description>Hi:&lt;BR /&gt;
  I believe the problem is not with the IF statement, per se, but with understanding the difference between "execution-time" statements and "compile-time" statements. As explained in this documentation topic, the format statement is a "declarative" statement that only gets used by SAS one time in a program -- at compile time.&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001225397.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001225397.htm&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Perhaps you meant to create the variable NAALR_BND from NAALR_SCR by using the PUT function with the appropriate format.   Something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data table5;&lt;BR /&gt;
  set table4;&lt;BR /&gt;
  length naalr_bnd $10;&lt;BR /&gt;
              &lt;BR /&gt;
  if bsnss_unt_id = 702 then do; &lt;BR /&gt;
     naalr_bnd=put(naalr_scr, naalrs.);&lt;BR /&gt;
  end;&lt;BR /&gt;
  else if bsnss_unt_id = 803 then do;&lt;BR /&gt;
    naalr_bnd= put(naalr_scr, naalra.);&lt;BR /&gt;
  end;&lt;BR /&gt;
  else do; &lt;BR /&gt;
     naalr_bnd = naalr_scr; /* this will be an unformatted value */&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
If you could possibly have more than 2 values for bsnss_unt_id, you might want to code a final ELSE condition.&lt;BR /&gt;
cynthia</description>
    <pubDate>Wed, 21 Oct 2009 22:34:35 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-10-21T22:34:35Z</dc:date>
    <item>
      <title>Help with a if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-a-if-then-statement/m-p/76454#M22172</link>
      <description>I'm a new user to SAS and am in the process of updating someone elses code, for the most part no issues, except this one which has left me puzzled. I'm running a data step that is adding new fields (only showing one in my example) and applying formats run earlier as part of a Proc Format process.&lt;BR /&gt;
&lt;BR /&gt;
Issue: When the process runs, only one of the formats is pickedup. Meaning, all records regardless of bsnss_unt_id get the same format . . . any help would be appreciated &lt;BR /&gt;
&lt;BR /&gt;
data Table5;&lt;BR /&gt;
set Table4;&lt;BR /&gt;
&lt;BR /&gt;
naalr_bnd = naalr_scr;&lt;BR /&gt;
&lt;BR /&gt;
/* groups naalr band */&lt;BR /&gt;
if bsnss_unt_id = 702 then do; &lt;BR /&gt;
format naalr_bnd naalrs.;&lt;BR /&gt;
end;&lt;BR /&gt;
else if bsnss_unt_id = 803 then do;&lt;BR /&gt;
format naalr_bnd naalra.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
endrsubmit;&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
value naalra&lt;BR /&gt;
0 - 0 = '01_000-000'&lt;BR /&gt;
1 - 349 = '02_001-349'&lt;BR /&gt;
350 - 354 = '03_350-354'&lt;BR /&gt;
355 - 359 = '04_355-359'&lt;BR /&gt;
360 - 364 = '05_360-364'&lt;BR /&gt;
365 - 369 = '06_365-369'&lt;BR /&gt;
370 - 374 = '07_370-374'&lt;BR /&gt;
375 - 379 = '08_375-379'&lt;BR /&gt;
380 - 384 = '09_380-384'&lt;BR /&gt;
385 - 389 = '10_385-389'&lt;BR /&gt;
390 - 394 = '11_390-394'&lt;BR /&gt;
395 - 399 = '12_395-399'&lt;BR /&gt;
400 - 404 = '13_400-404'&lt;BR /&gt;
405 - 409 = '14_405-409'&lt;BR /&gt;
410 - 414 = '15_410-414'&lt;BR /&gt;
415 - 419 = '16_415-419'&lt;BR /&gt;
420 - 424 = '17_420-424'&lt;BR /&gt;
425 - 429 = '18_425-429'&lt;BR /&gt;
430 - 434 = '19_430-434'&lt;BR /&gt;
435 - 439 = '20_435-439'&lt;BR /&gt;
440 - high= '21_440-999 '&lt;BR /&gt;
other = 'missing';&lt;BR /&gt;
&lt;BR /&gt;
value naalrs&lt;BR /&gt;
0 - 384 = '01_000-384'&lt;BR /&gt;
385 - 399 = '02_385-399'&lt;BR /&gt;
400 - 414 = '03_400-414'&lt;BR /&gt;
415 - 424 = '04_415-424'&lt;BR /&gt;
425 - 459 = '05_425-459'&lt;BR /&gt;
460 - high= '6_460+'&lt;BR /&gt;
other = 'missing';</description>
      <pubDate>Wed, 21 Oct 2009 21:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-a-if-then-statement/m-p/76454#M22172</guid>
      <dc:creator>NewUserFrank</dc:creator>
      <dc:date>2009-10-21T21:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-a-if-then-statement/m-p/76455#M22173</link>
      <description>Hi:&lt;BR /&gt;
  I believe the problem is not with the IF statement, per se, but with understanding the difference between "execution-time" statements and "compile-time" statements. As explained in this documentation topic, the format statement is a "declarative" statement that only gets used by SAS one time in a program -- at compile time.&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001225397.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001225397.htm&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Perhaps you meant to create the variable NAALR_BND from NAALR_SCR by using the PUT function with the appropriate format.   Something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data table5;&lt;BR /&gt;
  set table4;&lt;BR /&gt;
  length naalr_bnd $10;&lt;BR /&gt;
              &lt;BR /&gt;
  if bsnss_unt_id = 702 then do; &lt;BR /&gt;
     naalr_bnd=put(naalr_scr, naalrs.);&lt;BR /&gt;
  end;&lt;BR /&gt;
  else if bsnss_unt_id = 803 then do;&lt;BR /&gt;
    naalr_bnd= put(naalr_scr, naalra.);&lt;BR /&gt;
  end;&lt;BR /&gt;
  else do; &lt;BR /&gt;
     naalr_bnd = naalr_scr; /* this will be an unformatted value */&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
If you could possibly have more than 2 values for bsnss_unt_id, you might want to code a final ELSE condition.&lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 21 Oct 2009 22:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-a-if-then-statement/m-p/76455#M22173</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-21T22:34:35Z</dc:date>
    </item>
  </channel>
</rss>

