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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.