BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
priya_05
Calcite | Level 5

Hello,

i am new to sas and i have one problem.

 

I have employee table

 

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;

from this i get the following output

 

Capture.PNG

 

Now i want to add third column which shows the table name "Employee" in front of every record

 

Capture1.PNG

 

Could you please help me with this

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Use Datastep witn INDSNAME= set option

 

data temp;
set employee indsname=name;
tablename=scan(name,2);
run;

 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Use Datastep witn INDSNAME= set option

 

data temp;
set employee indsname=name;
tablename=scan(name,2);
run;

 

priya_05
Calcite | Level 5

Thank you so much. It works 

PGStats
Opal | Level 21

Do you mean something like this?

 

proc sql;
alter table Employee
add table_name char(16) ;
update employee set table_name="Employee";
quit;
PG
Tom
Super User Tom
Super User

The INDSNAME option on the SET statement will help with doing something like that.

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 6814 views
  • 3 likes
  • 5 in conversation