<?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: How to make a new database with variables from 2 other databases in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405150#M98580</link>
    <description>&lt;P&gt;Right, so this code:&lt;/P&gt;
&lt;PRE&gt;Libname m 'M:\Thesis data';&lt;/PRE&gt;
&lt;P&gt;Is fine. Then we add a datastep which sets two datasets within that library together:&lt;/P&gt;
&lt;PRE&gt;data want;
  set m.dataset1 (keep=vara varb)
      m.dataset2 (keep=vara varb);
run;&lt;/PRE&gt;
&lt;P&gt;This will set dataset2 under dataset1 in the output dataset called want.&amp;nbsp; It will select only vara (made up as you wont provide any test data) and varb from each dataset.&amp;nbsp; It assumes dataset1 and 2 exist in that library, both have the same two variables which are the same.&amp;nbsp; This will work.&amp;nbsp; You could also do:&lt;/P&gt;
&lt;PRE&gt;data want (keep=vara varb);
  set m.dataset1 m.dataset2;
run;&lt;/PRE&gt;
&lt;P&gt;So what is the question regarding this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You second question was variables have different names, if so then you would use a rename:&lt;/P&gt;
&lt;PRE&gt;data want;
  set m.dataset1 (keep=vara height)
      m.dataset2 (keep=vara height rename=(length=height));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To add, this code:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;data m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;datasetZ&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  set&lt;/SPAN&gt; m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;datasetX (&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;respno height&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
      m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;datasetY &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;respno height&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Will take all the data from datasetX keeping only respno and height.&amp;nbsp; Then it will take all the data from datasetY keeping only respno and height.&amp;nbsp; Then it will put the data from the datasetY &lt;U&gt;under&lt;/U&gt; datasetX.&amp;nbsp; So you will see that data further down the table.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2017 10:30:21 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-10-18T10:30:21Z</dc:date>
    <item>
      <title>How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405127#M98573</link>
      <description>&lt;P&gt;Hi! For my thesis I have to harmonise data from two different databases, but I don't need all data from both databases. My question is what is the easiest way to do this? I don't know how to pick one variable from the database X and the same variable from database Y and put it in new database Z? How can I do that, without putting all the variables from X and Y in database Z? The databases have different names for the same variables (e.g. database X = height and database Y = length). Here are some syntaxes I used, but these give errors..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*database X same as database Y*;&lt;BR /&gt;DATA database X;&lt;BR /&gt;SET database X;&lt;BR /&gt;LABEL person_id = respno;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*database Y same as database X*;&lt;BR /&gt;DATA database Y;&lt;BR /&gt;SET database Y;&lt;BR /&gt;LABEL length = height;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Interleaving*;&lt;BR /&gt;DATA database Z;&lt;BR /&gt;SET database X database Y;&lt;BR /&gt;by height respno;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Concatenating*;&lt;BR /&gt;DATA database Z;&lt;BR /&gt;SET&amp;nbsp;&lt;SPAN&gt;database X database Y&lt;/SPAN&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*One-to-one reading and one-to-one merging*;&lt;BR /&gt;DATA database Z;&lt;BR /&gt;SET database X;&lt;BR /&gt;SET database Y;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA database Z;&lt;BR /&gt;MERGE database X database Y;&lt;BR /&gt;BY respno;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;And I need to put a lot of variables from X and Y in database Z. Is there an easy way to change the names of the variables which are the same in databases X and Y (but have a different name, as already mentioned with height) and to put these variables in database Z? I hope my question is clear and someone can help me.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks! Oh and i use SAS version 9.3&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 08:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405127#M98573</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-10-18T08:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405133#M98574</link>
      <description>&lt;P&gt;What do you mean by database?&amp;nbsp; Is the data stored in a database like Oracle or Postgre or something like that, or is the data in SAS?&lt;/P&gt;
&lt;P&gt;How much SAS knowledge do you have, as the code you give is wrong on a few levels, might be worth running through the SAS video help to get some basics.&amp;nbsp;&amp;nbsp;As you haven't given me anything to work with here (i.e. example data or what you want to do with it) I will just show some general examples - assumes the data is in SAS:&lt;/P&gt;
&lt;PRE&gt;libname mylib "c:\path_to_data";&lt;/PRE&gt;
&lt;P&gt;The above creates a library reference pointing to a physical location on your computer/network.&amp;nbsp; This is how SAS knows where to look for data.&amp;nbsp; We can then use this too set (put one under the other) datasets together (say there is dataset a and b):&lt;/P&gt;
&lt;PRE&gt;data want;
  set mylib.a (keep=vara varb)
      mylib.b (keep=vara varb);
run;&lt;/PRE&gt;
&lt;P&gt;You will see I only keep the variables I want.&amp;nbsp; This requires both sets of variables are the same type and length.&lt;/P&gt;
&lt;P&gt;To merge data you first need to ensure both are sorted, then merge by key variables (take the above example, but merge on id and keep only varc from b):&lt;/P&gt;
&lt;PRE&gt;data want;
  merge mylib.a (keep=id vara varb)
        mylib.b (keep=id varc);&lt;BR /&gt;  by id;
run;&lt;/PRE&gt;
&lt;P&gt;These are quite basic and fundamental things which is why I suggest looking at the video tutorials and learning Base SAS a bit more.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 09:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405133#M98574</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-18T09:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405136#M98575</link>
      <description>&lt;P&gt;Thanks for your reply! I understand what you're saying. The databases I talk about are databases in SAS format. And I have (hopefully) basic knowledge of SAS. That's why I think I'm missing something here..&amp;nbsp;When I do this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA m.combined;
SET m.database X  (keep=height respo)
    m.database Y  (keep=height respo);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get these errors:&amp;nbsp;&lt;BR /&gt;ERROR: The variable height in the DROP, KEEP, or RENAME list has never been referenced.&lt;BR /&gt;ERROR: The variable respo in the DROP, KEEP, or RENAME list has never been referenced.&lt;BR /&gt;ERROR: The variable height in the DROP, KEEP, or RENAME list has never been referenced.&lt;BR /&gt;ERROR: The variable respo in the DROP, KEEP, or RENAME list has never been referenced.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What does this mean? I look for it on the internet, but can't solve it for my own data. Database X and Y both have the variables height and respo in them.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 09:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405136#M98575</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-10-18T09:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405138#M98576</link>
      <description>&lt;P&gt;If "m" is the name of the library assigned to the directory in which the data&lt;STRONG&gt;sets&lt;/STRONG&gt; "X" and "Y" are stored, than what is "database"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now you try to combine the datasets m.database, work.x, m.database and work.y - maybe not what you want to do.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 09:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405138#M98576</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-18T09:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405142#M98577</link>
      <description>&lt;P&gt;Yes, I'm sorry, I mean dataset! And m is the location where SAS needs to look for both datasets X and Y.&lt;/P&gt;&lt;P&gt;Let's make it more clear, I want to have a dataset Z in SAS like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Respno&lt;/TD&gt;&lt;TD&gt;Height&lt;/TD&gt;&lt;TD&gt;Length&lt;/TD&gt;&lt;TD&gt;Othervariable1&lt;/TD&gt;&lt;TD&gt;Othervariable2&lt;/TD&gt;&lt;TD&gt;Othervariable3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;All respno from datasetx&lt;/TD&gt;&lt;TD&gt;All height from datasetx&lt;/TD&gt;&lt;TD&gt;All length from datasetx&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;etc&lt;/TD&gt;&lt;TD&gt;etc&lt;/TD&gt;&lt;TD&gt;etc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;All respno&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;from&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;datasety&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;All height from datasety&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;SPAN&gt;All length from&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;datasety&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;etc&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;etc&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;etc&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I do this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA m.Z;
SET m.X 	(keep=respno height)
    m.Y         (keep=respno height);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I only get the respno&amp;nbsp;from dataset X and no respno&amp;nbsp;from dataset Y or height from both datasets..&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 10:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405142#M98577</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-10-18T10:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405144#M98578</link>
      <description>&lt;P&gt;Please use the training facilities available, you are missing some fundamental knowledge.&amp;nbsp; This code:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token keyword"&gt;SET&lt;/SPAN&gt; m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;dataset X 	&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;respno height&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;Is invalid.&amp;nbsp; To reference a dataset you first create a library reference - refer to my post.&amp;nbsp; This library reference is the first part preceeding the .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second part is the physical name of the dataset.&amp;nbsp; So, if on your network/computer you have a sas dataset called X, which will look something like: x.sas7bdat, then you reference this by first creating a library reference to the network/computer location and then using the code:&lt;/P&gt;
&lt;PRE&gt;set m.x (keep=respno height)&lt;/PRE&gt;
&lt;P&gt;You will see there is not dataset or database word in there, simply &amp;lt;library reference&amp;gt;.&amp;lt;datasetname&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a fundamental concept which is learnt in episode 1 of SAS training.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 10:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405144#M98578</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-18T10:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405146#M98579</link>
      <description>&lt;P&gt;Yes, I understand what you are saying. I already made a library m:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname m 'M:\Thesis data';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Dataset X and dataset Y are fictitious, because I can't give too much information about my thesis. But the datasets are in the map thesis data. In real these datasets have a different name. So I hope it makes it more clear and someone can help with my questions.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 10:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405146#M98579</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-10-18T10:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405150#M98580</link>
      <description>&lt;P&gt;Right, so this code:&lt;/P&gt;
&lt;PRE&gt;Libname m 'M:\Thesis data';&lt;/PRE&gt;
&lt;P&gt;Is fine. Then we add a datastep which sets two datasets within that library together:&lt;/P&gt;
&lt;PRE&gt;data want;
  set m.dataset1 (keep=vara varb)
      m.dataset2 (keep=vara varb);
run;&lt;/PRE&gt;
&lt;P&gt;This will set dataset2 under dataset1 in the output dataset called want.&amp;nbsp; It will select only vara (made up as you wont provide any test data) and varb from each dataset.&amp;nbsp; It assumes dataset1 and 2 exist in that library, both have the same two variables which are the same.&amp;nbsp; This will work.&amp;nbsp; You could also do:&lt;/P&gt;
&lt;PRE&gt;data want (keep=vara varb);
  set m.dataset1 m.dataset2;
run;&lt;/PRE&gt;
&lt;P&gt;So what is the question regarding this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You second question was variables have different names, if so then you would use a rename:&lt;/P&gt;
&lt;PRE&gt;data want;
  set m.dataset1 (keep=vara height)
      m.dataset2 (keep=vara height rename=(length=height));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To add, this code:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;data m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;datasetZ&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  set&lt;/SPAN&gt; m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;datasetX (&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;respno height&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
      m&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;datasetY &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;respno height&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Will take all the data from datasetX keeping only respno and height.&amp;nbsp; Then it will take all the data from datasetY keeping only respno and height.&amp;nbsp; Then it will put the data from the datasetY &lt;U&gt;under&lt;/U&gt; datasetX.&amp;nbsp; So you will see that data further down the table.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 10:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405150#M98580</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-18T10:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405155#M98581</link>
      <description>&lt;P&gt;HI Hovliza.&amp;nbsp; As an aside, like RW9 I would recommend some of the SAS videos, e-Learning (PG1) and popular post “&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_blank"&gt;Maxims of Maximally Efficient SAS Programmers&lt;/A&gt;” by KurtBremser – “Learning to read the documentation will enhance your problem-solving skills by orders of magnitude.”&amp;nbsp; From the ERROR: The variable respo in the DROP, KEEP, or RENAME list has never been referenced, your issue may be with variables height in X and length in Y if you want to concatenate these as one variable in the combined dataset you need to use the RENAME data set option (&lt;A href="http://documentation.sas.com/?docsetId=allprodslang&amp;amp;docsetTarget=syntaxByType-datasetOption.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p14jnvw8bco6o7n1m0m63mdiik2h"&gt;http://documentation.sas.com/?docsetId=allprodslang&amp;amp;docsetTarget=syntaxByType-datasetOption.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p14jnvw8bco6o7n1m0m63mdiik2h&lt;/A&gt; ) i.e. SET m.y (RENAME=(length=height));&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 10:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405155#M98581</guid>
      <dc:creator>Jeremy_Browne</dc:creator>
      <dc:date>2017-10-18T10:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405168#M98582</link>
      <description>&lt;P&gt;Read the log, the notes contain the number of observations read from each dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 11:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405168#M98582</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-18T11:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405169#M98583</link>
      <description>&lt;P&gt;Yes, my formulation is not that good..&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname m 'M:\Thesis data';
RUN;

*X same as Y*;
DATA m.X;
SET m.X;
RENAME person_id = respno;
RUN;

*Y same as X*;
DATA m.Y;
SET m.Y;
RENAME length = height;
RUN;

DATA m.Z;
SET m.Y    (keep=respno height)
    m.X	   (keep=respno height);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get a table with respno&amp;nbsp;for both dataset X and Y and height only for Y. I get the error;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: The variable height in the DROP, KEEP, or RENAME list has never been referenced.&lt;/P&gt;&lt;P&gt;But height is in dataset X..&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 11:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405169#M98583</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-10-18T11:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405170#M98584</link>
      <description>&lt;P&gt;Read the log.&amp;nbsp; Look at the output data.&amp;nbsp; Look at proc contents data=m.X; Look at the RENAME documentation – an option in the set statement i.e. in parentheses (RENAME=(old-name-1=new-name-1));&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 11:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405170#M98584</guid>
      <dc:creator>Jeremy_Browne</dc:creator>
      <dc:date>2017-10-18T11:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405283#M98585</link>
      <description>&lt;P&gt;Don’t code in the style you’re currently using, where the data set name in the SET is the same as the DATA statement. It makes mistakes really hard to find and you run the risk of destroying your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Set have;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect thats already happened. I suggest recreating your original data sets, then retrying this SET statement with the RENAME.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And read the chapter in the documentation on Combining Data sets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p15jvywi5avt3cn1bee8r6c33ux1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p15jvywi5avt3cn1bee8r6c33ux1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 17:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405283#M98585</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-18T17:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a new database with variables from 2 other databases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405285#M98586</link>
      <description>And there’s a difference between the terms database and data set with respect to SAS. They can be one and the same but typically databases have multiple datasets, not a single one.</description>
      <pubDate>Wed, 18 Oct 2017 17:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-new-database-with-variables-from-2-other-databases/m-p/405285#M98586</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-18T17:14:01Z</dc:date>
    </item>
  </channel>
</rss>

