<?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: Create new variables failed with if/then in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148272#M29338</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, if your data are EXACTLY as shown, I'd think you'd need something like the following (note: I modified your height calculation):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat hgunit $23.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID wg wgunit $&amp;nbsp;&amp;nbsp; hg&amp;nbsp;&amp;nbsp; hgunit &amp;amp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 203&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64.5 In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 202.4 Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64.5 In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 198&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 184&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 95&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;2 188&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 67&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;2 174.8 Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 162.56&amp;nbsp;&amp;nbsp;&amp;nbsp; Centimeters&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; weightkg=wg;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if wgunit='Lb' then weightkg=wg*0.4535924;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else weightkg=wg;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if hgunit="In (12 inches = 1 foot)" then heightm=hg/39.370;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else heightm=hg/100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 Oct 2014 00:42:14 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2014-10-30T00:42:14Z</dc:date>
    <item>
      <title>Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148268#M29334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a excel file like below:&lt;/P&gt;&lt;P&gt;ID wg wgunit&amp;nbsp;&amp;nbsp; hg&amp;nbsp;&amp;nbsp; hgunit&lt;/P&gt;&lt;P&gt;1 203&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64.5 In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 202.4 Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64.5 In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 198&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 184&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 95&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;2 188&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 67&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;2 174.8 Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 67&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to make variable with same unit. Here is my syntax:&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; weightkg=wg;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if wgunit='lb' then weightkg=wg*0.4535924;&lt;/P&gt;&lt;P&gt;&amp;nbsp; heightm=hg/100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if hgunit='in' then heightm=hg*2.5/100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;but output showed:&lt;/P&gt;&lt;P&gt;weightkg heightm &lt;/P&gt;&lt;P&gt;203.000&amp;nbsp; 0.6450 &lt;/P&gt;&lt;P&gt;202.400&amp;nbsp; 0.6450 &lt;/P&gt;&lt;P&gt;198.000&amp;nbsp; 0.6400 &lt;/P&gt;&lt;P&gt;184.000&amp;nbsp; 0.6400 &lt;/P&gt;&lt;P&gt;95.000&amp;nbsp;&amp;nbsp; 0.6400 &lt;/P&gt;&lt;P&gt;188.000 0.6700 &lt;/P&gt;&lt;P&gt;174.800 0.6700&lt;/P&gt;&lt;P&gt;I tried to debug my syntax, but it doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for helping me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 20:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148268#M29334</guid>
      <dc:creator>xinjian</dc:creator>
      <dc:date>2014-10-29T20:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148269#M29335</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;String comparison tests are case sensitive in SAS. "lb" is not equal to "Lb".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Never assume strings are always capitalized uniformly.&amp;nbsp; Use the UPCASE function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF UPCASE(wgunit) = "LB" THEN weightkg=.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;conversely:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF LOWCASE(wgunit)='lb' THEN weightkg=&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 21:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148269#M29335</guid>
      <dc:creator>rickpaulos</dc:creator>
      <dc:date>2014-10-29T21:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148270#M29336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried all versions of LCASE or UCASE, it showed same result. I am wondering why heightm=0.6 and etc. I need someone to help me figuring out the problem.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Oct 2014 00:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148270#M29336</guid>
      <dc:creator>xinjian</dc:creator>
      <dc:date>2014-10-30T00:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148271#M29337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you are trying something like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if wgunit='Lb' then weightkg=wg*0.4535924;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else weightkg=wg;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; if hgunit='In' then heightm=hg*2.5/100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else heightm=hg/100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Oct 2014 00:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148271#M29337</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-30T00:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148272#M29338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, if your data are EXACTLY as shown, I'd think you'd need something like the following (note: I modified your height calculation):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat hgunit $23.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID wg wgunit $&amp;nbsp;&amp;nbsp; hg&amp;nbsp;&amp;nbsp; hgunit &amp;amp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 203&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64.5 In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 202.4 Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64.5 In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 198&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 184&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;1 95&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;2 188&amp;nbsp;&amp;nbsp;&amp;nbsp; Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 67&amp;nbsp;&amp;nbsp;&amp;nbsp; In (12 inches = 1 foot)&lt;/P&gt;&lt;P&gt;2 174.8 Lb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 162.56&amp;nbsp;&amp;nbsp;&amp;nbsp; Centimeters&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; weightkg=wg;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if wgunit='Lb' then weightkg=wg*0.4535924;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else weightkg=wg;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if hgunit="In (12 inches = 1 foot)" then heightm=hg/39.370;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else heightm=hg/100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Oct 2014 00:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148272#M29338</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-10-30T00:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148273#M29339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In SAS I believe the proper functions are upcase and lowcase function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a SQL query the upper and lower functions also work.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Oct 2014 00:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148273#M29339</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-30T00:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148274#M29340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Duh, yeah. UPCASE.&amp;nbsp; UCASE is for Visual Basic.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Oct 2014 01:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148274#M29340</guid>
      <dc:creator>rickpaulos</dc:creator>
      <dc:date>2014-10-30T01:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables failed with if/then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148275#M29341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi &lt;A href="mailto:Stat@sas"&gt;Stat@sas&lt;/A&gt; and Arthur,&lt;/P&gt;&lt;P&gt;Both ways worked very good and got same result. Many thanks for your expertise.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Oct 2014 01:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-failed-with-if-then/m-p/148275#M29341</guid>
      <dc:creator>xinjian</dc:creator>
      <dc:date>2014-10-30T01:48:19Z</dc:date>
    </item>
  </channel>
</rss>

