<?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 name variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245779#M309283</link>
    <description>&lt;P&gt;Maybe you could try NATURE left join:&lt;/P&gt;
&lt;P&gt;Assuming there is only one variable ID in common in both datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table sys1&lt;BR /&gt;as select &amp;nbsp;&lt;STRONG&gt;*&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;from sys as a &lt;STRONG&gt;nature&lt;/STRONG&gt; left join Ret_Buy_fix_TP_notrail_H4 as b ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jan 2016 01:12:58 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-01-25T01:12:58Z</dc:date>
    <item>
      <title>Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245749#M309280</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a simple question. When I merge data A&amp;nbsp;and data B&amp;nbsp;and want to take a number of variables in B.&lt;/P&gt;
&lt;P&gt;Yes, I will list all variables needed but Is there any way I dont have to repeated by type "B." B.var1, B.var2...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table sys1&lt;BR /&gt;as select a.*, var1, var2 var3 var4&lt;/P&gt;
&lt;P&gt;from sys as a left join Ret_Buy_fix_TP_notrail_H4 as b&lt;/P&gt;
&lt;P&gt;on a.key=b.key;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2016 22:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245749#M309280</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-01-24T22:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245753#M309281</link>
      <description>&lt;P&gt;What you are doing will only work if all of the variables you choose are not in dataset A also. If any are then you have to specify from which dataset you want to read them.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2016 23:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245753#M309281</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-01-24T23:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245769#M309282</link>
      <description>&lt;P&gt;A bit of a trick - use the FEEDBACK option on your proc SQL statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then grab the code from the log and modify it as necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql feedback;
select a.*, b.*
from table1 as A
left join as table2 as B
on a.id=b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2016 00:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245769#M309282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-25T00:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245779#M309283</link>
      <description>&lt;P&gt;Maybe you could try NATURE left join:&lt;/P&gt;
&lt;P&gt;Assuming there is only one variable ID in common in both datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table sys1&lt;BR /&gt;as select &amp;nbsp;&lt;STRONG&gt;*&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;from sys as a &lt;STRONG&gt;nature&lt;/STRONG&gt; left join Ret_Buy_fix_TP_notrail_H4 as b ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 01:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245779#M309283</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-25T01:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245783#M309284</link>
      <description>&lt;P&gt;The issue is there are like 100 variable and I only want to take say 60 variables from that file B to the new file and I dont want to keep typing b. b. b. ....&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 01:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245783#M309284</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-01-25T01:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245784#M309285</link>
      <description>&lt;P&gt;Then use the following code and pick up the variable name you need into a macro variable via SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have(obs=0) out=temp;
 var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;............. into : list separated by ','&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 01:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245784#M309285</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-25T01:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245845#M309286</link>
      <description>&lt;P&gt;You could write a short utility macro as shown below and put it&amp;nbsp;into your&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/syntaxidx/68719/HTML/default/index.htm#/documentation/cdl//en/mcrolref/67912/HTML/default/p12b2qq72dkxpsn1e19y57emerr6.htm" target="_blank"&gt;SASAUTOS&lt;/A&gt;&amp;nbsp;library, so that it is automatically available in the future.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro b(list);
  b.%sysfunc(tranwrd(%cmpres(&amp;amp;list),%str( ),%str(,b.)))
%mend b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can write your select statement like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select a.*, %b(var1 var2 var3 var4)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the macro expression will resolve to &lt;FONT face="courier new,courier"&gt;b.var1,b.var2,b.var3,b.var4&lt;FONT face="arial,helvetica,sans-serif"&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;With variations of this macro you could be able to specify the alias (&lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; in the above example) as a macro parameter or to deal with &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm" target="_blank"&gt;variable lists&lt;/A&gt;&amp;nbsp;in order to reduce tedious typing to a minimum.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Edit: Added &lt;FONT face="courier new,courier"&gt;%cmpres&lt;/FONT&gt; so as to make macro B robust against inadvertent double spaces in the list of variable names.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 10:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245845#M309286</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-25T10:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL name variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245851#M309287</link>
      <description>&lt;P&gt;Why do you have a dataset with 100 variables? &amp;nbsp;I tend to advise on using normalised data structures (long rather than wide) as it makes programming easier, and SQL is specifically designed to work with normalised and relational datasets. &amp;nbsp;If this is due to a transpose - most likely - then don't use SQL as your code will not be easy. &amp;nbsp;Use datastep as datastep is designed to work with tables and provides functionality to work with wide tables - called arrays. &amp;nbsp;But it depends on the data which you haven't shown an example of (in the form of a datastep).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 11:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-name-variables/m-p/245851#M309287</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-25T11:04:22Z</dc:date>
    </item>
  </channel>
</rss>

