DATA Step, Macro, Functions and more

if some variables are duplicated

Reply
Contributor
Posts: 47

if some variables are duplicated

I have a table as below:

 

  id        term        table

  2          2015      bal

  2          2016      bal

  2          2016      tas

  3          2014      som

  3          2015      som

 4           2015     som

 4           2016     bal

 4           2016      cim

 

i need if same id and same term change the table name as 'BOTH'  like the table as below

 

id        term        table

  2          2015      bal

  2          2016      BOTH

  3          2014      som

  3          2015      som

 4           2015     som

 4           2016     BOTH

 

 

Super User
Super User
Posts: 7,970

Re: if some variables are duplicated

Hi,

 

proc transpose data=have out=want prefix=var;
  by id term;
  var table;
run;
data want (drop=name var1 var2);
  set want;
  table=ifc(missing(var2),var1,"BOTH");
run;
Super User
Posts: 10,035

Re: if some variables are duplicated

data have;
input id        term        table $;
cards;
  2          2015      bal
  2          2016      bal
  2          2016      tas
  3          2014      som
  3          2015      som
 4           2015     som
 4           2016     bal
 4           2016      cim
;
run;

data want;
 set have;
 by id term;
 if not (first.term and last.term) then  table='BOTH';
 if first.term;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 644 views
  • 0 likes
  • 3 in conversation