<?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 create primary key while creating table using select * from in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473170#M30679</link>
    <description>&lt;P&gt;Yes you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the query builder window of SAS Enterprise Guide, go to the Options window.&lt;/P&gt;
&lt;P&gt;In the field labeled options you can enter SAS Data Set Options. One of them allows you to create indexes. Use the following text:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;index=(yourColumn / unique)&lt;/PRE&gt;
&lt;P&gt;here is a sample of the code generated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_CLASS(index=(name/unique)) AS 
   SELECT t1.Name, 
          t1.Sex, 
          t1.Age, 
          t1.Height, 
          t1.Weight
      FROM SASHELP.CLASS t1;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please be aware, that if your column does not have unique values an error is generated, and the table will not be created.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jun 2018 21:08:33 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2018-06-25T21:08:33Z</dc:date>
    <item>
      <title>How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472913#M30673</link>
      <description>&lt;P&gt;I am trying to create a table using select * from. Can I create primary key in the same step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to&amp;nbsp;do it without using alter table or proc datasets or creating table first with primary key and inserting data into it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;Create table abc as select * from sashelp.class;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 10:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472913#M30673</guid>
      <dc:creator>Ishaan</dc:creator>
      <dc:date>2018-06-25T10:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472920#M30674</link>
      <description>&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002294522.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002294522.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can apply primary keys when creating a new empty table.&amp;nbsp; Then you would insert data into that table:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table abc (...) constraint primary key(...);
  insert into abc select * from sashelp.class;
quit;&lt;/PRE&gt;
&lt;P&gt;Or you would use the alter table option.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 10:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472920#M30674</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-25T10:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472928#M30675</link>
      <description>&lt;P&gt;Thanks. But I am looking for something which I can use while selecting the data.&lt;/P&gt;&lt;P&gt;I have more than 200+ variable in source table. I am not willing to create the table first and than insert the data into it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 11:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472928#M30675</guid>
      <dc:creator>Ishaan</dc:creator>
      <dc:date>2018-06-25T11:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472934#M30677</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52673"&gt;@Ishaan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. But I am looking for something which I can use while selecting the data.&lt;/P&gt;
&lt;P&gt;I have more than 200+ variable in source table. I am not willing to create the table first and than insert the data into it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sometimes reading the documentation is time-saving, so have a look at the create table syntax. I don't think that separating create and insert will have a negative impact on run-time.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 11:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472934#M30677</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-06-25T11:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472948#M30678</link>
      <description>&lt;P&gt;As I said, consult the documentation.&amp;nbsp; As you will see it is not possible to create table metadata when selecting.&amp;nbsp; Create the table first, then insert data.&amp;nbsp; Or create the data then alter the table.&amp;nbsp; Either works, and has no impact really.&amp;nbsp; This is how it works in SQL, database or other.&amp;nbsp; You create a table, set properties, keys, indexes etc.&amp;nbsp; Then you add data to it.&amp;nbsp; If that's not to you taste, don't use SQL.&amp;nbsp; 200+ columns in one table is bad design choice.&amp;nbsp; Databases a RDBMS, meaning they are relational, data separated out into minimal storage, then have the ability to join data.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 12:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/472948#M30678</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-25T12:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473170#M30679</link>
      <description>&lt;P&gt;Yes you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the query builder window of SAS Enterprise Guide, go to the Options window.&lt;/P&gt;
&lt;P&gt;In the field labeled options you can enter SAS Data Set Options. One of them allows you to create indexes. Use the following text:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;index=(yourColumn / unique)&lt;/PRE&gt;
&lt;P&gt;here is a sample of the code generated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_CLASS(index=(name/unique)) AS 
   SELECT t1.Name, 
          t1.Sex, 
          t1.Age, 
          t1.Height, 
          t1.Weight
      FROM SASHELP.CLASS t1;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please be aware, that if your column does not have unique values an error is generated, and the table will not be created.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 21:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473170#M30679</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-06-25T21:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473242#M30687</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt; even if unique indexes and PK usually have the same use cases, they are not always interchangeable, like if you wish to create a FK in a related table.</description>
      <pubDate>Tue, 26 Jun 2018 06:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473242#M30687</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-06-26T06:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473243#M30688</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;you are right creating the unique index will not create the PK definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I guess there is no way around a second step to create the PK definition.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 06:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/473243#M30688</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-06-26T06:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/804956#M40470</link>
      <description>Hello,&lt;BR /&gt;Is it primary index?</description>
      <pubDate>Wed, 30 Mar 2022 06:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/804956#M40470</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-03-30T06:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/804963#M40471</link>
      <description>&lt;P&gt;Yes the sample code I provided creates a unique index on a column. That is not yet a PK definition.&lt;/P&gt;
&lt;P&gt;You would need to add the actual primary key deinition (which would also create the index, if it does not already exist).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
alter table new_class add primary key (name);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/804963#M40471</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2022-03-30T06:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create primary key while creating table using select * from</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/804989#M40473</link>
      <description>&lt;P&gt;Would something like below do the job for you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length my_key_var 8;
  array vars_ {200} 8;
  my_key_var=1;
run;

proc sql;
  create table abc like have;
quit;

proc datasets lib=work nolist nowarn;
  modify abc;
    ic create my_key_var_pk=primary key(my_key_var);
  run;
quit;

proc append data=have base=abc;
run;quit;

proc contents data=work.abc;
run;quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 09:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-primary-key-while-creating-table-using-select-from/m-p/804989#M40473</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-30T09:09:21Z</dc:date>
    </item>
  </channel>
</rss>

