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
Now i want to add third column which shows the table name "Employee" in front of every record
Could you please help me with this
Use Datastep witn INDSNAME= set option
data temp;
set employee indsname=name;
tablename=scan(name,2);
run;
Use Datastep witn INDSNAME= set option
data temp;
set employee indsname=name;
tablename=scan(name,2);
run;
Thank you so much. It works
Welcome to the SAS Communities 🙂
Read this: Where did it come from? Adding the source of each observation to a SAS data set
Do you mean something like this?
proc sql;
alter table Employee
add table_name char(16) ;
update employee set table_name="Employee";
quit;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.