<?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 How to add column with the table name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556294#M154965</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;i am new to sas and i have one problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have employee table&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.EMPLOYEE( 
first_name char(50),
last_name char(50) 
);

insert into WORK.EMPLOYEE
VALUES('PINTTO','KARLSSON')
VALUES('NATASHA','JOHANSSON')
VALUES('HARRY','BRUUN');

QUIT;

proc SQL;
CREATE TABLE WORK.TEMP AS
SELECT FIRST_NAME, LAST_NAME FROM WORK.EMPLOYEE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;from this i get the following output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 244px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29214i2E11717CDFD17A9A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i want to add third column which shows the table name "Employee" in front of every record&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 397px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29215iE835EF2BCCCDA951/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me with this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 May 2019 19:57:52 GMT</pubDate>
    <dc:creator>priya_05</dc:creator>
    <dc:date>2019-05-05T19:57:52Z</dc:date>
    <item>
      <title>How to add column with the table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556294#M154965</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;i am new to sas and i have one problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have employee table&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.EMPLOYEE( 
first_name char(50),
last_name char(50) 
);

insert into WORK.EMPLOYEE
VALUES('PINTTO','KARLSSON')
VALUES('NATASHA','JOHANSSON')
VALUES('HARRY','BRUUN');

QUIT;

proc SQL;
CREATE TABLE WORK.TEMP AS
SELECT FIRST_NAME, LAST_NAME FROM WORK.EMPLOYEE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;from this i get the following output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 244px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29214i2E11717CDFD17A9A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i want to add third column which shows the table name "Employee" in front of every record&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 397px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29215iE835EF2BCCCDA951/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me with this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 19:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556294#M154965</guid>
      <dc:creator>priya_05</dc:creator>
      <dc:date>2019-05-05T19:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to add column with the table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556295#M154966</link>
      <description>&lt;P&gt;Use Datastep witn INDSNAME= set option&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set employee indsname=name;
tablename=scan(name,2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 20:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556295#M154966</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-05T20:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to add column with the table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556297#M154967</link>
      <description>&lt;P&gt;Welcome to the SAS Communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read this:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2015/08/03/indsname-option.html" target="_self"&gt;Where did it come from? Adding the source of each observation to a SAS data set&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 20:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556297#M154967</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-05T20:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to add column with the table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556301#M154969</link>
      <description>&lt;P&gt;Do you mean something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
alter table Employee
add table_name char(16) ;
update employee set table_name="Employee";
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 May 2019 21:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556301#M154969</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-05-05T21:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to add column with the table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556337#M154982</link>
      <description>&lt;P&gt;The INDSNAME option on the SET statement will help with doing something like that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EMPLOYEE ;
  length first_name $50 last_name $50 ;
  infile cards dsd dlm='|' truncover ;
  input first_name last_name;
cards;
PINTTO|KARLSSON
NATASHA|JOHANSSON
HARRY|BRUUN
;

data temp;
  length table_name indsname $41 ;
  set employee indsname=indsname;
  table_name=indsname;
run;

proc print data=temp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 03:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/556337#M154982</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-06T03:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to add column with the table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/557399#M155387</link>
      <description>&lt;P&gt;Thank you so much. It works&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 10:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-column-with-the-table-name/m-p/557399#M155387</guid>
      <dc:creator>priya_05</dc:creator>
      <dc:date>2019-05-09T10:30:52Z</dc:date>
    </item>
  </channel>
</rss>

