BookmarkSubscribeRSS Feed
lerdem
Quartz | Level 8

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

 

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Ksharp
Super User
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1492 views
  • 0 likes
  • 3 in conversation