BookmarkSubscribeRSS Feed
Ziba
Calcite | Level 5

Dear All, 

my question might be too simple but I actually have some trouble figuring it out...I hope I can get some help from you guys, thanks in advance. 

 

 data count;
 set patent_list;
  by permno;
  if first.permno=1 then NumCit=0;
  NumCit+ncites;
  run;

I used the above code to calculated the accumulating number of citation for each company(see the table below). But what I want is only the total number of the citation. (that means I dont need other rows indicating the current accumulated values)

 

Now I want to create two columns, one is the total number of the patents for each company (permno is the unique identifier, so you can count it until the permno change to different permno, ) and the total number of citations that each company received for its all applied patents. 

for example, company D has 10 patents(count till permno changes) and 28 citation in total. So, as a final result, I want to keep all the variables from the table, and add these two new columns. 

 

 

namepermnomerged_file_datepatnumfdatencites
A113422/9/2004   
B117603/17/2003   
C1232011/30/2004   
D4415010/20/200464127473/22/20019
D4415010/20/200464127463/22/20015
D4415010/20/200464683734/20/20003
D4415010/20/200464059893/22/20012
D4415010/20/200464059903/22/20013
D4415010/20/200465542433/22/20016
D4415010/20/2004690539611/20/2003 
D4415010/20/200468748022/25/2003 
D4415010/20/2004700093512/22/2003 
D4415010/20/200469491629/23/2002 
E472714/1/2003   
F550605/20/200465502876/7/20020
G654966/23/200465374594/20/200011
G654966/23/200465622497/10/2001 
G654966/23/200466828756/18/2001 
G654966/23/2004636505711/1/19993
G654966/23/2004646843911/1/19999
G654966/23/2004640993011/1/19990
F659644/8/2003595261910/30/19988
F659644/8/200359800579/15/199811
F659644/8/200362048249/22/19984
F659644/8/200362118441/7/19993
H674323/31/2004657280510/13/19990
H674323/31/2004665623010/11/20010
H674323/31/2004668603712/16/19991
H674323/31/2004632265410/13/19993
H674323/31/200468399379/25/2002 
I755975/19/200366792737/23/2001 
I755975/19/2003662837811/9/1999 
I755975/19/200362647577/23/19984
I755975/19/2003628059610/1/19992
I755975/19/200360356896/24/19983
2 REPLIES 2
Tom
Super User Tom
Super User

Use the LAST.PERMNO flag to tell which observation to output.

To count the observations just use another counter variable that you increment by 1 each time.

data count;
  set patent_list;
  by permno;
  if first.permno=1 then call missing(NumPat,NumCit);
  NumCit+ncites+0;
  NumPat+1;
  if last.permno;
run;
Ziba
Calcite | Level 5



data logit.count; set logit.patent_company; by permno; if first.permno then Numcit = 0; numcit + ncites; if first.permno then Numpat = 0; if patnum ne '' then Numpat + 1; else Numpat + 0; if last.permno; run;

hey, thanks for your code. Just made several changes.

I used the above code as I dont want to count patent number if the company doesnt have any patents.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2423 views
  • 2 likes
  • 2 in conversation