BookmarkSubscribeRSS Feed
andersongwjr
Calcite | Level 5

Hi there,

 

I am working with publication data. Starting with a set of cited publications, I am trying to characterize the set of citing publications that cite the cited publications. I am trying to define the following variables. 

 

New Key Word: defined as new if a key word has never before appeared in the key word list of the cited article or previous citations to the cited article; old otherwise.

 

Total New Key Words: total number of new keywords in citing article.

 

DATA cited;
INFILE CARDS;
INPUT CITED_ID KW_1 $ KW_2 $ KW_3 $;
CARDS;
1000 xx1 xx2 xx3
1001 aa1 aa2 aa3
;
run;

 

DATA citing;
INFILE CARDS;
INPUT CITED_ID CITING_ID KW_1 $ KW_2 $ KW_3 $;
CARDS;
1000 2000 xx1 xx2
1000 2001 yy1 xx2 yy2
1000 2002 xx3 yy1 yy2
1000 2003 yy2 xx2 zz1
1001 2004 aa1 aa2 xx1
1001 2005 aa1 bb1 bb2
1001 2006 aa1 bb2 cc1
;
run;

 

Desired Data 
CITED_ID CITING_ID NEW_KW TOT_NEW_KW
1000 2000 0 0
1000 2001 1 2
1000 2002 0 0
1000 2003 1 1
1001 2004 1 1
1001 2005 1 2
1001 2006 1 1

 

Thanks,

Gary

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

 

data CITED;
  input CITED_ID KW_1 $ KW_2 $ KW_3 $;
cards;
1000 xx1 xx2 xx3
1001 aa1 aa2 aa3
run;

data CITING;
  infile cards missover;
  input CITED_ID CITING_ID KW_1 $ KW_2 $ KW_3 $;
cards;
1000 2000 xx1 xx2
1000 2001 yy1 xx2 yy2
1000 2002 xx3 yy1 yy2
1000 2003 yy2 xx2 zz1
1001 2004 aa1 aa2 xx1
1001 2005 aa1 bb1 bb2
1001 2006 aa1 bb2 cc1
run;

data WANT; 
  retain CITED_LIST ;
  length CITED_LIST $80;
  merge CITED 
        CITING(rename=(KW_1=K1 KW_2=K2 KW_3=K3));
  by CITED_ID;
  TOT_NEW_KW=0;
  if first.CITED_ID then do;
    CITED_LIST=catx(' ',of KW_1-KW_3);
    TOT_NEW_KW=0;
  end;    
  array K [3];
  do I=1 to 3;
    if K[I] ne ' ' & ^findw( CITED_LIST, K[I], , 'st') then do;       
      TOT_NEW_KW+1;
      CITED_LIST=catx(' ', CITED_LIST, K[I]);
    end;  
  end;  
  keep CITED_ID CITING_ID TOT_NEW_KW;
run;

SAS Output

CITED_ID CITING_ID TOT_NEW_KW
1000 2000 0
1000 2001 2
1000 2002 0
1000 2003 1
1001 2004 1
1001 2005 2
1001 2006 1

 

 

 

Ksharp
Super User
DATA cited;
INFILE CARDS;
INPUT CITED_ID KW_1 $ KW_2 $ KW_3 $;
CARDS;
1000 xx1 xx2 xx3
1001 aa1 aa2 aa3
;
run;
 
DATA citing;
INFILE CARDS truncover;
INPUT CITED_ID CITING_ID KW_1 $ KW_2 $ KW_3 $;
CARDS;
1000 2000 xx1 xx2
1000 2001 yy1 xx2 yy2
1000 2002 xx3 yy1 yy2
1000 2003 yy2 xx2 zz1
1001 2004 aa1 aa2 xx1
1001 2005 aa1 bb1 bb2
1001 2006 aa1 bb2 cc1
;
run;

proc transpose data=cited out=key(where=(col1 is not missing));
by cited_id;
var kw_:;
run;
data want;
 if _n_=1 then do;
  if 0 then set key;
  declare hash h(dataset:'key');
  h.definekey('cited_id','col1');
  h.definedone();
 end;
set citing;
array x{*} kw_: ;
tot_new_kw=0;
do i=1 to dim(x);
 if not missing(x{i}) then do;
  col1=x{i};
  if h.check() ne 0 then do;
   tot_new_kw+1;h.add();
  end;
 end;
end;
new_kw=(tot_new_kw ne 0);
drop _name_ i col1;
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
  • 744 views
  • 0 likes
  • 3 in conversation