<?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: proc sql: WHERE statement multiple columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415607#M101942</link>
    <description>&lt;P&gt;Hi Surya,&lt;/P&gt;&lt;P&gt;I run this command but by doing this I am losing 1 from second row&amp;nbsp; for&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;lifestyle_j&amp;nbsp; variable. When I printed need dataset it gave me just one row. It should have given me that value for&amp;nbsp;&amp;nbsp;lifestyle_j&amp;nbsp; variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2017 18:59:43 GMT</pubDate>
    <dc:creator>Pooja2</dc:creator>
    <dc:date>2017-11-22T18:59:43Z</dc:date>
    <item>
      <title>proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415596#M101933</link>
      <description>&lt;P&gt;proc sql;&lt;BR /&gt;create table&amp;nbsp;combined as&lt;BR /&gt;select lifestyle_a, lifestyle_f, lifestyle_g, lifestyle_h, lifestyle_i, lifestyle_j, lifestyle_k, lifestyle_l,&lt;BR /&gt;lifestyle_m, lifestyle_n, lifestyle_o, lifestyle_p, lifestyle_q, lifestyle_r, lifestyle_s, lifestyle_u, lifestyle_v, lifestyle_y, lifestyle_aa, lifestyle_ab, lifestyle_ac&lt;BR /&gt;from plot1&lt;BR /&gt;where lifestyle_a,&amp;nbsp;&lt;SPAN&gt;lifestyle_f, lifestyle_g, lifestyle_h, lifestyle_i, lifestyle_j, lifestyle_k, lifestyle_l,&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lifestyle_m, lifestyle_n, lifestyle_o, lifestyle_p, lifestyle_q, lifestyle_r, lifestyle_s, lifestyle_u, lifestyle_v, lifestyle_y, lifestyle_aa, lifestyle_ab, lifestyle_ac&amp;nbsp;&lt;/SPAN&gt;IN (1, 2, 3,4);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a table where all the columns have just there four values. I would appreciate community help here,&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415596#M101933</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T18:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415598#M101934</link>
      <description>&lt;P&gt;This would probably be much easier in a data step, use an array and WHICHC. But, if the values are numeric and you want them between 1 and 4 required, you could calculate the max/min and as long as those are between 1 and 4 I think it works the same.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you post data we can test that approach.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415598#M101934</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T18:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415601#M101936</link>
      <description>&lt;P&gt;Thank you for your email. Please find attached the data set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415601#M101936</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T18:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415602#M101937</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use Dictionary.Columns and structure your where condition and then put that in a macro. See code below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input lifestyle_a lifestyle_f lifestyle_g lifestyle_h lifestyle_i lifestyle_j lifestyle_k lifestyle_l;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 1 2 3 4&lt;BR /&gt;3 4 5 6 7 1 3 5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select name||" IN (1,2,3,4)" INTO: Condition SEPARATED BY " AND "&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname="WORK" and memname="HAVE" and upcase(name) like "LIFESTYLE_%";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE NEED AS&lt;BR /&gt;SELECT * FROM HAVE&lt;BR /&gt;WHERE &amp;amp;Condition.;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415602#M101937</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-11-22T18:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415603#M101938</link>
      <description>&lt;P&gt;And I format them by following value&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;Value NegFeel&lt;BR /&gt;0 = 'Never'&lt;BR /&gt;1 = 'Less than Monthly'&lt;BR /&gt;2 = 'Monthly'&lt;BR /&gt;3 = 'Weekly'&lt;BR /&gt;4 = 'Daily or almost daily'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415603#M101938</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T18:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415605#M101940</link>
      <description>&lt;P&gt;I run this command but by doing this I am losing 1 from second row&amp;nbsp; for&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;lifestyle_j&amp;nbsp; variable. When I printed need dataset it gave me just one row. It should have given me that value for&amp;nbsp;&amp;nbsp;lifestyle_j&amp;nbsp; variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415605#M101940</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T18:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415607#M101942</link>
      <description>&lt;P&gt;Hi Surya,&lt;/P&gt;&lt;P&gt;I run this command but by doing this I am losing 1 from second row&amp;nbsp; for&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;lifestyle_j&amp;nbsp; variable. When I printed need dataset it gave me just one row. It should have given me that value for&amp;nbsp;&amp;nbsp;lifestyle_j&amp;nbsp; variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415607#M101942</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T18:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415608#M101943</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I run this command but by doing this I am losing 1 from second row&amp;nbsp; for&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;lifestyle_j&amp;nbsp; variable. When I printed need dataset it gave me just one row. It should have given me that value for&amp;nbsp;&amp;nbsp;lifestyle_j&amp;nbsp; variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ok. Then it's unclear what you're trying to do here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you work off the example data&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;&amp;nbsp;posted and show what output you'd expect from that input?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415608#M101943</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T19:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415611#M101945</link>
      <description>&lt;P&gt;Okay.&amp;nbsp;For example if I have following dataset. I want to create a data set where I have all the cells where these columns have values in 1 to 4. Hope that is clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input lifestyle_a lifestyle_f lifestyle_g lifestyle_h lifestyle_i lifestyle_j lifestyle_k lifestyle_l;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 1 2 3 4&lt;BR /&gt;3 4 5 6 7 1 3 5&lt;/P&gt;&lt;P&gt;2 3 4 2 4 5 6 7&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 2 3 3 9 8 8 8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415611#M101945</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T19:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415616#M101948</link>
      <description>&lt;P&gt;Is this the output your looking for?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Input data */&lt;BR /&gt;Data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input lifestyle_a lifestyle_f lifestyle_g lifestyle_h lifestyle_i lifestyle_j lifestyle_k lifestyle_l;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 1 2 3 4&lt;BR /&gt;3 4 5 6 7 1 3 5&lt;BR /&gt;2 3 4 2 4 5 6 7&lt;BR /&gt;1 2 3 3 9 8 8 8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;/* Method -1 */&lt;BR /&gt;proc sql;&lt;BR /&gt;select name||" IN (1,2,3,4)" INTO: Condition SEPARATED BY " AND "&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname="WORK" and memname="HAVE" and upcase(name) like "LIFESTYLE_%";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE NEED1 AS&lt;BR /&gt;SELECT * FROM HAVE&lt;BR /&gt;WHERE &amp;amp;Condition.;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* Method-2 */&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select count(*),name INTO:count ,: Vars SEPARATED BY " "&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname="WORK" and memname="HAVE" and upcase(name) like "LIFESTYLE_%";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA need2(drop=i);&lt;BR /&gt;set have;&lt;BR /&gt;array Var_Check {&amp;amp;count.} &amp;amp;Vars.;&lt;BR /&gt;do i = 1 to dim(Var_Check);&lt;BR /&gt;IF Var_Check{i} in (1,2,3,4);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415616#M101948</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-11-22T19:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415620#M101949</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415620#M101949</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2017-11-22T19:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415723#M102004</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Okay.&amp;nbsp;For example if I have following dataset. I want to create a data set where I have all the cells where these columns have values in 1 to 4. Hope that is clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input lifestyle_a lifestyle_f lifestyle_g lifestyle_h lifestyle_i lifestyle_j lifestyle_k lifestyle_l;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 1 2 3 4&lt;BR /&gt;3 4 5 6 7 1 3 5&lt;/P&gt;
&lt;P&gt;2 3 4 2 4 5 6 7&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 2 3 3 9 8 8 8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You still didn't say which of those four observations meet your criteria. The point of examples is to clarify the words.&lt;/P&gt;
&lt;P&gt;Assuming what is want is to only find the first observation you could do something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ls1-ls8 ;
datalines;
1 2 3 4 1 2 3 4
3 4 5 6 7 1 3 5
2 3 4 2 4 5 6 7 
1 2 3 3 9 8 8 8
;

proc print data=have ;
 where 4 &amp;gt;= max(ls1,ls2,ls3,ls4,ls5,ls6,ls7,ls8)
   and 1 &amp;lt;= min(ls1,ls2,ls3,ls4,ls5,ls6,ls7,ls8)
   and 8 = n(ls1,ls2,ls3,ls4,ls5,ls6,ls7,ls8)
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One problem with doing this using a WHERE statement is that the WHERE statement does not support variable lists.&amp;nbsp; It would much easier to type using a IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  if  4 &amp;gt;= max(of ls1-ls8)
   and 1 &amp;lt;= min(of ls1-ls8)
   and 8 = n(of ls1-ls8)
 ;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Nov 2017 01:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415723#M102004</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-23T01:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: WHERE statement multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415724#M102005</link>
      <description>&lt;P&gt;You don't have to work that hard. SAS can count,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;/* Method-2 */&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select count(*),name INTO:count ,: Vars SEPARATED BY " "&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname="WORK" and memname="HAVE" and upcase(name) like "LIFESTYLE_%";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA need2(drop=i);&lt;BR /&gt;set have;&lt;BR /&gt;array Var_Check {&amp;amp;count.} &amp;amp;Vars.;&lt;BR /&gt;do i = 1 to dim(Var_Check);&lt;BR /&gt;IF Var_Check{i} in (1,2,3,4);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC SQL can count how many records it found.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name INTO :Vars SEPARATED BY " "
  from dictionary.columns
  where libname="WORK" and memname="HAVE" and upcase(name) like "LIFESTYLE_%"
;
%let count=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you really don't need to calculate &amp;amp;COUNT at all because SAS can also count how many variables you have listed in a array statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array Var_Check &amp;amp;Vars.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Nov 2017 01:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-multiple-columns/m-p/415724#M102005</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-23T01:13:22Z</dc:date>
    </item>
  </channel>
</rss>

