<?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 into with a where clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430856#M106511</link>
    <description>&lt;P&gt;Figured it out. where clause should go at the end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct FieldName into : male_name_list separated by ',' from master_data where male = 1;
quit;

%put &amp;amp;male_name_list;

data results_final;
set results_final;
summary_male= sum(&amp;amp;male_name_list);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Jan 2018 11:17:26 GMT</pubDate>
    <dc:creator>ss59</dc:creator>
    <dc:date>2018-01-25T11:17:26Z</dc:date>
    <item>
      <title>proc sql into with a where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430855#M106510</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to select variable names and want to sum them to create a new variable. Following code works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct FieldName into : name_list separated by ',' from master_data;
  quit;

%put &amp;amp;name_list;

data results_final;
set results_final;
summary = sum(&amp;amp;name_list);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I want to do the same thing with an additional condition that involves a where clause. This is not working. could you please help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct FieldName where male = 1 into : male_name_list separated by ',' from master_data;
quit;

%put &amp;amp;male_name_list;

data results_final;
set results_final;
summary_male= sum(&amp;amp;male_name_list);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 11:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430855#M106510</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2018-01-25T11:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql into with a where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430856#M106511</link>
      <description>&lt;P&gt;Figured it out. where clause should go at the end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct FieldName into : male_name_list separated by ',' from master_data where male = 1;
quit;

%put &amp;amp;male_name_list;

data results_final;
set results_final;
summary_male= sum(&amp;amp;male_name_list);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 11:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430856#M106511</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2018-01-25T11:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql into with a where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430857#M106512</link>
      <description>&lt;P&gt;put the where after the from&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 11:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430857#M106512</guid>
      <dc:creator>Rhys</dc:creator>
      <dc:date>2018-01-25T11:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql into with a where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430862#M106516</link>
      <description>&lt;P&gt;That's a very odd way to be coding, does your data have columns for each of the names?&amp;nbsp; You would find it far simpler to normalise that data, then just sum based on logic in one simpler datastep, you can drop all the macro and proc sql then.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 11:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430862#M106516</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-25T11:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql into with a where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430893#M106525</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a solution that avoids using a list of names in a macrovariable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data persons;
input name $ male;
cards;
John 1
Mary 0
Peter 1
Robert 1
Jane 0
Lucy 0
William 1
Richard 1
Anna 0
;
run;

data results;
input John Mary Michael Peter Sylvia Robert Jane Lucy William Charlotte Richard Annna;
cards;
3 4 2 3 5 4 2 5 3 4 1 4
;
run;


proc sql noprint;
    SELECT count(*) INTO :nmales
    FROM persons
    WHERE male=1;
quit;

data want;
    set results;
    array a_names(&amp;amp;nmales.) $ _TEMPORARY_;

    if _N_=1 then do i=1 by 1 until (eof);
        set persons (where=(male=1)) end=eof;
        a_names(i)=name;
    end;

    do i=1 to dim(a_names);
        total+vvaluex(a_names(i));
    end;

    drop i name male;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 13:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-into-with-a-where-clause/m-p/430893#M106525</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-01-25T13:27:00Z</dc:date>
    </item>
  </channel>
</rss>

