Hello Everyone,
I want to keep the last 5 trading day data in each year from 1998 to 2017. I am using daily VIX data series from Yahoo Finance. I downloaded the data from the following link. Could you please help me in doing the job in SAS?
1. Sort your data set descending so that you can take the first 5 of each group.
2. Use a counter variable to take the first five records.
You can create the counters as illustrated here:
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
Or below:
EDIT: Note that this assumes you have a single record for each date, if you don't the answer is different, but the link above illustrates how to count with multiple variables in your BY group.
@nazmul wrote:
Hello Everyone,
I want to keep the last 5 trading day data in each year from 1998 to 2017. I am using daily VIX data series from Yahoo Finance. I downloaded the data from the following link. Could you please help me in doing the job in SAS?
Hello @nazmul,
Your question requires more details before experts can help. Can you revise your question to include more information?
Review this checklist:
To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message. From there you can adjust the title and add more details to the body of the message. Or, simply reply to this message with any additional information you can supply.
SAS experts are eager to help -- help them by providing as much detail as you can.
This prewritten response was triggered for you by fellow SAS Support Communities member @PeterClemmensen
.Hello @nazmul,
Your question requires more details before experts can help. Can you revise your question to include more information?
Review this checklist:
To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message. From there you can adjust the title and add more details to the body of the message. Or, simply reply to this message with any additional information you can supply.
SAS experts are eager to help -- help them by providing as much detail as you can.
This prewritten response was triggered for you by fellow SAS Support Communities member @PeterClemmensen
.1. Sort your data set descending so that you can take the first 5 of each group.
2. Use a counter variable to take the first five records.
You can create the counters as illustrated here:
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
Or below:
EDIT: Note that this assumes you have a single record for each date, if you don't the answer is different, but the link above illustrates how to count with multiple variables in your BY group.
@nazmul wrote:
Hello Everyone,
I want to keep the last 5 trading day data in each year from 1998 to 2017. I am using daily VIX data series from Yahoo Finance. I downloaded the data from the following link. Could you please help me in doing the job in SAS?
If the data are already sorted by stock, and ascending date, the descending sort can be an expensive solution, compared to:
data want (drop=_:);
merge have (firstobs=1)
have (firstobs=6 keep=stock rename=(stock=_stock5));
if stock^=_stock5;
run;
Just look ahead 5 observations to see whether the look-ahead stock (_stock5) is the same as the current stock. The "firstobs=1" parameter is the default value, but I put it in there to draw attention to what is actually happening. Two data streams (offset by 5 observations) are being read synchronously.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.