<?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: SQL - where a variable is in another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746997#M234421</link>
    <description>&lt;P&gt;To make it clearer which variable you are referencing you can use ALIAS prefix on the variable references.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;3146  data male class ;
3147    set sashelp.class;
3148    output class;
3149    if sex='M' then output male;
3150  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.MALE has 10 observations and 5 variables.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.03 seconds


3151
3152  proc sql;
3153  delete from class a
3154    where a.name in (select b.name from male b)
3155  ;
NOTE: 10 rows were deleted from WORK.CLASS.

3156  quit;
&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Jun 2021 12:14:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-06-10T12:14:32Z</dc:date>
    <item>
      <title>SQL - where a variable is in another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746963#M234403</link>
      <description>&lt;P&gt;I have come across the following code (modified naming for ease of interpretation):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
   Delete from MyTable
   Where variable1 in (select variable1 from To_Delete);
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My interpretation of this code is the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We delete all observations (rows) where variable1 from the table MyTable (notice there is a variable1 in two different tables and hence the variable1 could differ from the two tables) takes the values of variable1 from the table ToDelete.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So, to make it easier to understand, I could write the pseudo-code:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   Delete from MyTable
   Where variable1_MyTable in (select variable_1_ToDelete from To_Delete);
Quit;&lt;/PRE&gt;
&lt;P&gt;Now it is clear that we delete all observations where&amp;nbsp;variable1_MyTable takes the values from:&amp;nbsp;variable_1_ToDelete.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If i understand it correctly, this seems like a powerful concept.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Questions:&amp;nbsp;&lt;BR /&gt;1. Is my understanding of it correct?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Where can I read some documentation about this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 09:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746963#M234403</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-10T09:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - where a variable is in another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746987#M234413</link>
      <description>&lt;P&gt;1. Yes your understanding is correct.&lt;BR /&gt;2.For more details you can look here&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/titlepage.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/titlepage.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 11:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746987#M234413</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-10T11:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - where a variable is in another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746997#M234421</link>
      <description>&lt;P&gt;To make it clearer which variable you are referencing you can use ALIAS prefix on the variable references.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;3146  data male class ;
3147    set sashelp.class;
3148    output class;
3149    if sex='M' then output male;
3150  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.MALE has 10 observations and 5 variables.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.03 seconds


3151
3152  proc sql;
3153  delete from class a
3154    where a.name in (select b.name from male b)
3155  ;
NOTE: 10 rows were deleted from WORK.CLASS.

3156  quit;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Jun 2021 12:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/746997#M234421</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-10T12:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - where a variable is in another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/747028#M234430</link>
      <description>&lt;P&gt;Thank you Tom, very clear!&lt;BR /&gt;&lt;BR /&gt;1. When aliasing, you are omitting AS? If I would like to be very clear, I would write:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
delete from class &lt;STRONG&gt;as&lt;/STRONG&gt; a
where a.name in (select b.name from male &lt;STRONG&gt;as&lt;/STRONG&gt; b);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. The method used here (Defining the values of a variable from another variable), it can in many situations produce the same result as an inner join for instance? Am I thinking about it correctly or what do you think is the main virtue of this method?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 14:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/747028#M234430</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-10T14:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - where a variable is in another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/747038#M234434</link>
      <description>&lt;P&gt;SQL implementations differ on whether you can (or are required to) include AS keyword.&lt;/P&gt;
&lt;P&gt;Personally I do not use it when defining an alias for a dataset (table) but do use it when setting the name of a variable (column).&amp;nbsp; The AS keyword is required when creating a dataset (table) from the results of a query with the CREATE TABLE syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
  select a.name as Student_Name
  from sashelp.class a
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Jun 2021 14:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-where-a-variable-is-in-another/m-p/747038#M234434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-10T14:22:32Z</dc:date>
    </item>
  </channel>
</rss>

