<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317762#M69588</link>
    <description>&lt;P&gt;AS can also be used to give a new name to a column or expression :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
create table Realestatefilter as
select 
	S.NAME as SubName,
	C.NAME as CharterName,
	APPROVYEAR,
	JURISDICTION,
	YEAROPEN,
	CITY
from 
	Subdivisionsort as S, 
	Chartersort as C
where S.APPROVYEAR = C.YEAROPEN;

select * from Realestatefilter;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Dec 2016 01:34:27 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-12-09T01:34:27Z</dc:date>
    <item>
      <title>PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317743#M69584</link>
      <description>&lt;P&gt;I am trying to pull all the varibales from the subdivisionsort and chartersort data sets yet only keep a couple ultimately but the variable NAME appears in both data sets. &amp;nbsp;I need both of them but I keep getting errors saying that the statement is too&amp;nbsp;ambiguous if I do not specify which data set to pull it from but when I put S. or C. in front of NAME sas says the variable NAME already exists in Realestatefilter. &amp;nbsp;I want to merge them where I am not sure which way is the best way to complete this task but none of the options below are working. &amp;nbsp;Any suggestions would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create table work.Realestatefilter as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select S.NAME,C.NAME,APPROVYEAR,JURISDICTION,YEAROPEN,CITY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from work.Subdivisionsort as S, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;work.Chartersort as C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;where S.APPROVYEAR=C.YEAROPEN;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Proc Print data=Realestatefilter;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create table work.Realestatefilter as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select NAME,APPROVYEAR,JURISDICTION,YEAROPEN,CITY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from work.Subdivisionsort as S, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;work.Chartersort as C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;where S.APPROVYEAR=C.YEAROPEN;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Proc Print data=Realestatefilter;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;BR /&gt;create table work.Realestatefilter as&lt;BR /&gt;select *&lt;BR /&gt;from work.Subdivisionsort (keep=NAME &amp;nbsp;&lt;SPAN&gt;APPROVYEAR&amp;nbsp;&lt;/SPAN&gt;JURISDICTION) as S,&lt;BR /&gt;work.Chartersort (keep= NAME YEAROPEN CITY) as C&lt;BR /&gt;where S.&lt;SPAN&gt;APPROVYEAR&lt;/SPAN&gt;=C.&lt;SPAN&gt;YEAROPEN&lt;/SPAN&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;Proc Print data=Realestatefilter;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 23:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317743#M69584</guid>
      <dc:creator>aweaver</dc:creator>
      <dc:date>2016-12-08T23:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317745#M69585</link>
      <description>&lt;P&gt;In the final SAS data set, they need to have different names. &amp;nbsp;If you want to keep both, you can give them different names, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;S.name as SubName, C.name as ChartName,&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 23:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317745#M69585</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-08T23:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317753#M69586</link>
      <description>So I need to do this in a separate data step or can I add that in somewhere&lt;BR /&gt;in this statement? Additionally, can you do a rename in the Proc sql&lt;BR /&gt;statement?&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Fri, 09 Dec 2016 00:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317753#M69586</guid>
      <dc:creator>aweaver</dc:creator>
      <dc:date>2016-12-09T00:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317762#M69588</link>
      <description>&lt;P&gt;AS can also be used to give a new name to a column or expression :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
create table Realestatefilter as
select 
	S.NAME as SubName,
	C.NAME as CharterName,
	APPROVYEAR,
	JURISDICTION,
	YEAROPEN,
	CITY
from 
	Subdivisionsort as S, 
	Chartersort as C
where S.APPROVYEAR = C.YEAROPEN;

select * from Realestatefilter;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2016 01:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317762#M69588</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-12-09T01:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317839#M69610</link>
      <description>&lt;P&gt;I would really suggest looking up some learning material on SQL, aliasing is a basic fundamental of SQL - in this case the alias becomes a variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would also avoid mixing Base SAS statements in SQL statements. &amp;nbsp;It works, but its neither good coding, nor is is compatible with anything outside SAS - i.e. if you were to connect to a DB, or want to copy the code somewhere else - so this&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;select *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from work.Subdivisionsort (keep=NAME &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;APPROVYEAR&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;JURISDICTION)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Becomes:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WORK.REALESTATEFILTER as
  select  S.NAME as S_NAME,
          coalesce(S.APPROVYEAR,C.YEAROPEN) as YEAR,
          S.JURISDICTION,
          C.NAME as C_NAME,
          C.CITY
  from    WORK.SUBDIVISIONSORT as S,
          WORK.CHARTERSORT as C
  where   S.APPROVYEAR=C.YEAROPEN;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that I coalesce() the joining variables, theres no need to have two variables with the same infomation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note also the consistent casing, indentations and such like to make code as readable as possible, and the avoidance of lazy programming techniques like select *. &amp;nbsp;Not sure why you need a proc print after each statement either, it doesn't add anything to the mix as you are creating datasets with each step?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 09:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317839#M69610</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-09T09:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317853#M69617</link>
      <description>Thank you!</description>
      <pubDate>Fri, 09 Dec 2016 10:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317853#M69617</guid>
      <dc:creator>aweaver</dc:creator>
      <dc:date>2016-12-09T10:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317869#M69623</link>
      <description>When I rename the variables like this is it just temporary or are they permanently renamed as I plan to use them in code after this statement?&lt;BR /&gt;&lt;BR /&gt;Thanks for your help&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Dec 2016 11:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/317869#M69623</guid>
      <dc:creator>aweaver</dc:creator>
      <dc:date>2016-12-09T11:40:19Z</dc:date>
    </item>
  </channel>
</rss>

