add variable from one dataset to another in one data step

Reply
Occasional Contributor
Posts: 12

add variable from one dataset to another in one data step

I have two datasets, and I'm trying to add one variable in dataset 'SURG' to dataset 'PROCEDURE'. The variable I want to add from SURG is 'type', which is a single character surgery code related to another variable in SURG, three character code 'maintype', which the file is sorted on. In PROCEDURE, there is a variable that is the same as 'maintype' but it is labelled 'descript'. There are more different types of 'maintype' than 'descript', so some of them are not in the PROCEDURE database.

 

Thanks (sorry, I realize it's confusing)

Super User
Super User
Posts: 9,599

Re: add variable from one dataset to another in one data step

Follow the guidance on posting a question, show test data in the form of a datastep of each dataset input, and what you expect to see as output - we cannot guess these.

 

From what you write something like:

proc sql;
  create table want as
  select   a.*,
           b.type
  from     procedure a
  left join surg b
  on       a.maintype=b.descript;
quit;
Super User
Posts: 23,661

Re: add variable from one dataset to another in one data step

Create a format from your lookup table and apply the format in a data step or PROC SQL.

 


@Angmar wrote:

I have two datasets, and I'm trying to add one variable in dataset 'SURG' to dataset 'PROCEDURE'. The variable I want to add from SURG is 'type', which is a single character surgery code related to another variable in SURG, three character code 'maintype', which the file is sorted on. In PROCEDURE, there is a variable that is the same as 'maintype' but it is labelled 'descript'. There are more different types of 'maintype' than 'descript', so some of them are not in the PROCEDURE database.

 

Thanks (sorry, I realize it's confusing)


 

Ask a Question
Discussion stats
  • 2 replies
  • 81 views
  • 0 likes
  • 3 in conversation