BookmarkSubscribeRSS Feed
adamlvkvist
Calcite | Level 5

I have a dataset of bond transactions and want each bond to occur at least 30 times during my time range. There is one variable that is unique for each bond (an CUSIP Id) that I should be able use to see if the bond occurs n times. In other words, from my (full) dataset I would like to create a new dataset that only contains bonds that trades n times. Additionally, from this new dataset, I would like to calculate the average daily bond price. Thus, I need to see how many times an bond is traded during one day, compute average price and create a new dataset with the average prices and only one "trade" per day. 

 

Could anyone please help a beginner?

Snip SAS.PNG 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do you want two new data sets or one?

 

There should be 30 occurences of CUSIP in the entire time range and not within each trade date, correct?

adamlvkvist
Calcite | Level 5
Two; the first reduces the full data set so each CUSIP occurs at least 30 times during the time range, the second data set reduces the first further so each CUSIP only "trades" once a day and the price is the average daily price.

There should be 30 occurences of CUSIP in the entire time range and not within each trade date, correct? - Exactly! 🙂
PeterClemmensen
Tourmaline | Level 20

Ok. See if you can use this as a template. Since I don't have your data, I use SASHELP.STOCKS to create some example data. I create it so IBM, Microsoft are traded more than Intel. 

 

data have;
   set sashelp.stocks;
   if stock in ('IBM', 'Microsoft') then do;
      output; output;
   end;
   else output;
run;

proc freq data = have;
   tables stock / nocum nopercent;
run;

snip.PNG

 

 

 

So in this example, I want at least 250 obs for a stock to include in the first data set (change this to 30)

 

proc sql;
   create table one as
   select * from have
   group by stock
   having n(stock) > 250;
quit; 

 

Next, I use this to create averages for each date. 

 

proc summary data = one nway;
   class date;
   var close;
   output out = want(drop = _:) mean =;
run;

 

Hope this helps 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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