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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 6663 views
  • 3 likes
  • 5 in conversation