<?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: Easiest way for multiple where clause for proc sql? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200237#M49999</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can get this done in one step, you have to build an array of PRICE and HOTEL for each NAME and export when you change NAME. I can't test now but this should not have too many errors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data SUMMARY ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array HOTELS [99] $20 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array PRICES [99]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1 nobs=NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if indexw(HOTEL, of HOTELS&lt;LI&gt;) = 0 then HOTELS[whichn(' ',of HOTELS&lt;/LI&gt;&lt;LI&gt;)]=HOTEL;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by NAME;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.NAME then call missing(of PRICES);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _POS=whichn(HOTEL ,of HOTELS&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRICES[_POS]=PRICE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.NAME then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop _: HOTEL PRICE;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Aug 2015 11:39:01 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2015-08-17T11:39:01Z</dc:date>
    <item>
      <title>Easiest way for multiple where clause for proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200235#M49997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a code that works but I wonder if there is a shortest way in sql to do the same that the code below. The data are totally fictive but suppose that there only 4 possible combinations of destination-hotel. Is it possible to obtain sammary dataset in only one step? Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;data example1;&lt;BR /&gt;input name $ destination $ hotel $ price;&lt;BR /&gt;datalines;&lt;BR /&gt;John Paris Ritz 1254&lt;BR /&gt;John New-York Belfort 4896&lt;BR /&gt;Mary Paris Eifel 2452&lt;BR /&gt;Mary London Olympic 6965&lt;BR /&gt;Steeve Paris Ritz 2152&lt;BR /&gt;Mike New-York Belfort 1515&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table step0 as&lt;BR /&gt;select distinct name&lt;BR /&gt;from example1&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table step1 as&lt;BR /&gt;select distinct name, price as price_t1&lt;BR /&gt;from example1&lt;BR /&gt;where destination ='Paris' and hotel='Ritz'&lt;BR /&gt;;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table step2 as&lt;BR /&gt;select distinct name, price as price_t2&lt;BR /&gt;from example1&lt;BR /&gt;where destination ='Paris' and hotel='Eifel'&lt;BR /&gt;;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table step3 as&lt;BR /&gt;select distinct name, price as price_t3&lt;BR /&gt;from example1&lt;BR /&gt;where destination ='London' and hotel='Olympic'&lt;BR /&gt;;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table step4 as&lt;BR /&gt;select distinct name, price as price_t4&lt;BR /&gt;from example1&lt;BR /&gt;where destination ='New-York' and hotel='Belfort'&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table summary as&lt;BR /&gt;SELECT *&lt;BR /&gt;FROM step0&lt;BR /&gt;LEFT JOIN step1 ON step0.name = step1.name&lt;BR /&gt;LEFT JOIN step2 ON step0.name = step2.name&lt;BR /&gt;LEFT JOIN step3 ON step0.name = step3.name&lt;BR /&gt;LEFT JOIN step4 ON step0.name = step4.name&lt;BR /&gt;;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2015 08:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200235#M49997</guid>
      <dc:creator>problems99</dc:creator>
      <dc:date>2015-08-17T08:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Easiest way for multiple where clause for proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200236#M49998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest you separate your calculating from your output.&amp;nbsp; SQL works on normalised data, whilst it is possible to get transposed data, it is not recommended or easy with SQL.&amp;nbsp; It is simple to get aggregates:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; NAME&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,DESTINATION&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,HOTEL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,sum(PRICE) as PRICE&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; EXAMPLE1&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by NAME&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,DESTINATION&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,HOTEL;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do note in the above indentation, alignements, closing steps with the right word (e.g. quit;).&lt;/P&gt;&lt;P&gt;The above gives you a list of the aggregates of the data, if you need this transposed in an output pdf or something then you can simply transpose the data, however if further processing is needed, then retain the normalised structure.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2015 08:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200236#M49998</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-08-17T08:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Easiest way for multiple where clause for proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200237#M49999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can get this done in one step, you have to build an array of PRICE and HOTEL for each NAME and export when you change NAME. I can't test now but this should not have too many errors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data SUMMARY ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array HOTELS [99] $20 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array PRICES [99]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1 nobs=NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if indexw(HOTEL, of HOTELS&lt;LI&gt;) = 0 then HOTELS[whichn(' ',of HOTELS&lt;/LI&gt;&lt;LI&gt;)]=HOTEL;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by NAME;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.NAME then call missing(of PRICES);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _POS=whichn(HOTEL ,of HOTELS&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRICES[_POS]=PRICE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.NAME then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop _: HOTEL PRICE;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2015 11:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200237#M49999</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-08-17T11:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Easiest way for multiple where clause for proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200238#M50000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I corrected a first error by line 11 with PRICES&lt;LI&gt; but there is still one with "if indexw" that I cannot solve.&lt;/LI&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;data SUMMARY ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; array HOTELS [99] $20 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; array PRICES [99]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1 nobs=NOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if indexw(HOTEL, of HOTELS&lt;LI&gt;) = 0 then HOTELS[whichn(' ',of HOTELS&lt;/LI&gt;&lt;LI&gt;)]=HOTEL;&lt;/LI&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by NAME;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.NAME then call missing(of PRICES&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _POS=whichn(HOTEL ,of HOTELS&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRICES[_POS]=PRICE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.NAME then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; drop _: HOTEL PRICE;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2015 12:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200238#M50000</guid>
      <dc:creator>problems99</dc:creator>
      <dc:date>2015-08-17T12:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Easiest way for multiple where clause for proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200239#M50001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few errors &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; . Fixed:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data SUMMARY2 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array HOTELS [9] $20 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array PRICES [9]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1 nobs=NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if whichc(HOTEL, of HOTELS&lt;LI&gt;) = 0 then HOTELS[whichc(' ',of HOTELS&lt;/LI&gt;&lt;LI&gt;)]=HOTEL;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _I=1 to NOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EXAMPLE1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by NAME;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.NAME then call missing(of PRICES&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _POS=whichc(HOTEL ,of HOTELS&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRICES[_POS]=PRICE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.NAME then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;keep NAME PRICES:;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort/index the data by NAME before.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2015 23:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Easiest-way-for-multiple-where-clause-for-proc-sql/m-p/200239#M50001</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-08-17T23:26:51Z</dc:date>
    </item>
  </channel>
</rss>

