Good morning,
I have a data set that gives me some forecast information by period for a series of stock tickers. However, each of the records shows the current date only. I want to create a file that shows me the current period and the next period all on the same line. The period dates will not be consistent for each stock unfortunately.
I attached an excel file that has the data that I have and what I'm looking for. Essentially, Just taking the next date for that ticker and pulling it back into the original row. So if the row has a February Date, and the next period is a March Date, I want to show the March Date on the February line too.
Thank you!!!
It does not look like "next" either. It appears that perhaps you mean to match on FPI as well as your ticker. Maybe.
Your example output really needs to provide more examples such as what would the result be for
AAPL 03783310 20FEB2020 EPS 7
AAPL 03783310 20FEB2020 EPS 8
AAPL 03783310 20FEB2020 EPS 9
AAPL 03783310 16JAN2020 EPS 6
And if your Measure variable plays any role in this you need to describe that as well.
Post the code in a code box opened on the forum with the </> or "running man" icon.
I am going to guess that perhaps you want something like:
proc sql; create table want as select a.ticker, a.cusip, a.statpers, a.measure, a.fpi ,b.statpers as odate from WORK.IBES_NEW_APPLE as a left join WORK.IBES_NEW_APPLE as b on a.ticker=b.ticker and a.fpi=b.fpi and intck('month',b.statpers,a.statpers) =1 order by a.ticker, a.statpers descending, a.fpi ; quit;
Most of us will not download and open a Microsoft Office file, as they are security threats. Please provide (a portion of) your data as SAS data step code, as explained in these instructions:
How to create a data step version of your data AKA generate sample data for forums
Noted! Let me see if I can get it to work. Currently its erroring out.
@anweinbe wrote:
Noted! Let me see if I can get it to work. Currently its erroring out.
Here's a different link
https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/
which may be more usable, sometimes people cannot download directly from github.
Data provided as screen captures is not usable.
Here is the data. My goal is to add an additional column so that the next period also shows on the row. For example, record 5 would show the january date as is, but a new column would show the february date.
AAPL | 03783310 | 20FEB2020 | EPS | 7 |
2 | AAPL | 03783310 | 20FEB2020 | EPS | 6 |
3 | AAPL | 03783310 | 20FEB2020 | EPS | 9 |
4 | AAPL | 03783310 | 20FEB2020 | EPS | 8 |
5 | AAPL | 03783310 | 16JAN2020 | EPS | 7 |
6 | AAPL | 03783310 | 16JAN2020 | EPS | 8 |
7 | AAPL | 03783310 | 16JAN2020 | EPS | 6 |
8 | AAPL | 03783310 | 16JAN2020 | EPS | 9 |
9 | AAPL | 03783310 | 19DEC2019 | EPS | 9 |
10 | AAPL | 03783310 | 19DEC2019 | EPS | 7 |
11 | AAPL | 03783310 | 19DEC2019 | EPS | 8 |
12 | AAPL | 03783310 | 19DEC2019 | EPS | 6 |
@anweinbe wrote:
Here is the data. My goal is to add an additional column so that the next period also shows on the row. For example, record 5 would show the january date as is, but a new column would show the february date.
AAPL 03783310 20FEB2020 EPS 7
2 AAPL 03783310 20FEB2020 EPS 6
3 AAPL 03783310 20FEB2020 EPS 9
4 AAPL 03783310 20FEB2020 EPS 8
5 AAPL 03783310 16JAN2020 EPS 7
6 AAPL 03783310 16JAN2020 EPS 8
7 AAPL 03783310 16JAN2020 EPS 6
8 AAPL 03783310 16JAN2020 EPS 9
9 AAPL 03783310 19DEC2019 EPS 9
10 AAPL 03783310 19DEC2019 EPS 7
11 AAPL 03783310 19DEC2019 EPS 8
12 AAPL 03783310 19DEC2019 EPS 6
If your "record 5" is showing the "February" date wouldn't that be PREVIOUS not NEXT?
And I suspect you are missing part of the description. What role does the variable that shows values of AAPL and possibly 03783310 play in this problem?
The data step as @PaigeMiller indicated would at least let us know what the variable names are to talk about.
Hopefully this is what you guys need. Sorry my SAS skills are very novice level.
The AAPL and the numbers are just unique identifiers for "Apple". Ideally I would have more stock symbols in the full file.
to simplify, I would like the following:
AAPL 03783310 20FEB2020 EPS 6 16JAN2020
It does not look like "next" either. It appears that perhaps you mean to match on FPI as well as your ticker. Maybe.
Your example output really needs to provide more examples such as what would the result be for
AAPL 03783310 20FEB2020 EPS 7
AAPL 03783310 20FEB2020 EPS 8
AAPL 03783310 20FEB2020 EPS 9
AAPL 03783310 16JAN2020 EPS 6
And if your Measure variable plays any role in this you need to describe that as well.
Post the code in a code box opened on the forum with the </> or "running man" icon.
I am going to guess that perhaps you want something like:
proc sql; create table want as select a.ticker, a.cusip, a.statpers, a.measure, a.fpi ,b.statpers as odate from WORK.IBES_NEW_APPLE as a left join WORK.IBES_NEW_APPLE as b on a.ticker=b.ticker and a.fpi=b.fpi and intck('month',b.statpers,a.statpers) =1 order by a.ticker, a.statpers descending, a.fpi ; quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.