<?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 Equivalent of IIF as in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82076#M256663</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Got a dataset &lt;STRONG&gt;Mdata.D2007_01&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Want to return from the same the following fields:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Customer&amp;nbsp;&amp;nbsp;&amp;nbsp; Product&amp;nbsp;&amp;nbsp;&amp;nbsp; Amount&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I need to add an additional field of Category in the end based on the figures in the last field of Amount as:&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 1000000,'Category 01',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 30000000,'Category 02',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 60000000,'Category 03',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 90000000,'Category 04',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 120000000,'Category 05',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 150000000,'Category 06',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 180000000,'Category 07',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 210000000,'Category 08',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 240000000,'Category 09',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 270000000,'Category 10',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 300000000,'Category 11',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 330000000,'Category 12',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 360000000,'Category 13','Category 14')))))))))))))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and have the result be saved to a temporary dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What could be the most appropriate code for the same?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Sep 2013 17:24:21 GMT</pubDate>
    <dc:creator>FarazA_Qureshi</dc:creator>
    <dc:date>2013-09-13T17:24:21Z</dc:date>
    <item>
      <title>Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82076#M256663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Got a dataset &lt;STRONG&gt;Mdata.D2007_01&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Want to return from the same the following fields:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Customer&amp;nbsp;&amp;nbsp;&amp;nbsp; Product&amp;nbsp;&amp;nbsp;&amp;nbsp; Amount&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I need to add an additional field of Category in the end based on the figures in the last field of Amount as:&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 1000000,'Category 01',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 30000000,'Category 02',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 60000000,'Category 03',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 90000000,'Category 04',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 120000000,'Category 05',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 150000000,'Category 06',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 180000000,'Category 07',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 210000000,'Category 08',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 240000000,'Category 09',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 270000000,'Category 10',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 300000000,'Category 11',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 330000000,'Category 12',&lt;/P&gt;&lt;P&gt;IIF(Amount &amp;lt; 360000000,'Category 13','Category 14')))))))))))))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and have the result be saved to a temporary dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What could be the most appropriate code for the same?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 17:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82076#M256663</guid>
      <dc:creator>FarazA_Qureshi</dc:creator>
      <dc:date>2013-09-13T17:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82077#M256664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use either a format or Select statement or If/Then statements.&lt;/P&gt;&lt;P&gt;Are you working in SQL or a data step?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think formats are the most efficient, especially if they're being reused in more than one place. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" title="http://www2.sas.com/proceedings/sugi30/001-30.pdf"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value amount_category&lt;/P&gt;&lt;P&gt; low - &amp;lt;1000000 = "Category 01"&lt;/P&gt;&lt;P&gt;1000000 - &amp;lt; 30000000 = "Category 02"&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;330000000 -&amp;lt; 360000000 = "Category 13"&lt;/P&gt;&lt;P&gt;other = "Category 14";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;new_variable=put(category, amount_category.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select *, put(category, amount_category.) as new_variable&lt;/P&gt;&lt;P&gt;from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 17:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82077#M256664</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-09-13T17:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82078#M256665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;as IIF is from thinking modifying data in the MS-access limitations...&lt;/P&gt;&lt;P&gt;Now thinking in SAS oppurtunities...&lt;/P&gt;&lt;P&gt;- If you have the format defined. You could possibly have no need to change data. &lt;/P&gt;&lt;P&gt;&amp;nbsp; Many procedures (eg report/tabluate) are accepting the format being defined there and it works like the data was changed (but not really)&amp;nbsp;&amp;nbsp; &lt;BR /&gt;This approach can save a lot of time as it is&amp;nbsp; bypassing the need for data conversions &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 20:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82078#M256665</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2013-09-13T20:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82079#M256666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Excellent reference to the Matchless Working Paper.&lt;/P&gt;&lt;P&gt;Sure do appreciate!&lt;/P&gt;&lt;P&gt;Thanx again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 21:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82079#M256666</guid>
      <dc:creator>FarazA_Qureshi</dc:creator>
      <dc:date>2013-09-13T21:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82080#M256667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By the way, is there any way to use the Put() function limits, values legend, determination as in PROC FORMAT in PROC SQL as well. I mean consider the following example where the Temp3 dataset is not created, and please see if you could help in finishing up the same more efficiently:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value Category low -&amp;lt; 1 = '1'&lt;/P&gt;&lt;P&gt;1 -&amp;lt; 30 = '2'&lt;/P&gt;&lt;P&gt;30 -&amp;lt; 60 = '3'&lt;/P&gt;&lt;P&gt;60 -&amp;lt; 90 = '4'&lt;/P&gt;&lt;P&gt;90 -&amp;lt; 120 = '5'&lt;/P&gt;&lt;P&gt;120 -&amp;lt; 150 = '6'&lt;/P&gt;&lt;P&gt;150 -&amp;lt; 180 = '7'&lt;/P&gt;&lt;P&gt;180 -&amp;lt; 210 = '8'&lt;/P&gt;&lt;P&gt;210 -&amp;lt; 240 = '9'&lt;/P&gt;&lt;P&gt;240 -&amp;lt; 270 = '10'&lt;/P&gt;&lt;P&gt;270 -&amp;lt; 300 = '11'&lt;/P&gt;&lt;P&gt;300 -&amp;lt; 330 = '12'&lt;/P&gt;&lt;P&gt;330 -&amp;lt; 360 = '13'&lt;/P&gt;&lt;P&gt;other = '14'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;value $ codefmt&lt;/P&gt;&lt;P&gt;'1'='Bucket 1'&lt;/P&gt;&lt;P&gt;'2'='Bucket 2'&lt;/P&gt;&lt;P&gt;'3'='Bucket 3'&lt;/P&gt;&lt;P&gt;'4'='Bucket 4'&lt;/P&gt;&lt;P&gt;'5'='Bucket 5'&lt;/P&gt;&lt;P&gt;'6'='Bucket 6'&lt;/P&gt;&lt;P&gt;'7'='Bucket 7'&lt;/P&gt;&lt;P&gt;'8'='Bucket 8'&lt;/P&gt;&lt;P&gt;'9'='Bucket 9'&lt;/P&gt;&lt;P&gt;'10'='Bucket 10'&lt;/P&gt;&lt;P&gt;'11'='Bucket 11'&lt;/P&gt;&lt;P&gt;'12'='Bucket 12'&lt;/P&gt;&lt;P&gt;'13'='Bucket 13'&lt;/P&gt;&lt;P&gt;'14'='Bucket 14'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;DATA Work.Temp2;&lt;/P&gt;&lt;P&gt;set FAQ.Data_2007_01;&lt;/P&gt;&lt;P&gt;tempcode=put(put(DPD, Category.), codefmt.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE Work.Temp3 as SELECT POS, &lt;STRONG&gt;put(put(DPD, Category.), codefmt.)&lt;/STRONG&gt; as Bucket from FAQ.Data_2007_01;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 21:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82080#M256667</guid>
      <dc:creator>FarazA_Qureshi</dc:creator>
      <dc:date>2013-09-13T21:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82081#M256668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a different format that assigns the ranges directly&lt;/P&gt;&lt;P&gt; value buckets&lt;/P&gt;&lt;P&gt;low -&amp;lt;1 = 'Bucket 1'&lt;/P&gt;&lt;P&gt;1 -&amp;lt; 30 = 'Bucket 2'&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and I'm not sure you need to create a new variable. One of the big advantages of formats is you can perform analysis or output with the format applied to the original variable and don't need new variables all of the time. Makes it easy to investigate groups by making a new format instead of new variables.&lt;/P&gt;&lt;P&gt;With the new Buckets format&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=faq.data_2007_01;&lt;/P&gt;&lt;P&gt;tables DPD;&lt;/P&gt;&lt;P&gt;format DPD buckets.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suppose you later decide you want to see what happens with the data in 3 groups.&lt;/P&gt;&lt;P&gt;Proc format;&lt;/P&gt;&lt;P&gt;value threebuckets&lt;/P&gt;&lt;P&gt;low -&amp;lt; 150 = 'Big bucket 1'&lt;/P&gt;&lt;P&gt;150 -&amp;lt; 300 ='Big bucket 2'&lt;/P&gt;&lt;P&gt;300 - high&amp;nbsp;&amp;nbsp; = 'Big bucket 3'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc freq data=faq.data_2007_01;&lt;/P&gt;&lt;P&gt;tables DPD;&lt;/P&gt;&lt;P&gt;format DPD threebuckets.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW your code examples should be using $codefmt. in the put statements. Also, your current Category format is going to assign missing to 14. If you don't have any missing then no problem but something to consider when using 'other'. You may actually want 360 - high = '14'.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 22:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82081#M256668</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-09-13T22:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent of IIF as in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82082#M256669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very nice, the idea of better performance limiting computer resource usage by using Formats is being got&lt;/P&gt;&lt;P&gt;Having them defined could be a very handy one wiht using the full (SAS) dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next level of this is Multi label formats. Using different classification / format recodings on the same data. &lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p1kkf0fl0y3yeon1qxyme7bp7hcn.htm" title="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p1kkf0fl0y3yeon1qxyme7bp7hcn.htm"&gt;Base SAS(R) 9.3 Procedures Guide, Second Edition&lt;/A&gt; ( &lt;A name="p1kkf0fl0y3yeon1qxyme7bp7hcn"&gt;&lt;/A&gt;Example 17: Using Multilabel Formats )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Sep 2013 06:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-of-IIF-as-in-SQL/m-p/82082#M256669</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2013-09-14T06:48:27Z</dc:date>
    </item>
  </channel>
</rss>

