BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anweinbe
Quartz | Level 8

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!!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
anweinbe
Quartz | Level 8

Noted! Let me see if I can get it to work. Currently its erroring out. 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
anweinbe
Quartz | Level 8

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.

 

DavePrinsloo
Pyrite | Level 9
could you provide an extra table with the wanted results, with the extra cloumn
ballardw
Super User

@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.

 


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.

anweinbe
Quartz | Level 8
DATA2DATASTEP DSN IBES_NEW_APPLE
DATA2DATASTEP FILE homesyranweinbe/create_WORK_IBES_NEW_APPLE_data.sas
DATA2DATASTEP FMT YES
DATA2DATASTEP FMTLIST STATPERS DATE9.
DATA2DATASTEP INPUTLIST TICKER:$6. CUSIP:$8. STATPERS:DATE9. MEASURE:$6. FPI:$1.
DATA2DATASTEP LBL YES
DATA2DATASTEP LBLLIST TICKER="IBES Ticker Symbol" CUSIP="CUSIP/SEDOL" STATPERS="I/B/E/S Statistical Period (SAS Format)" MEASURE="Measure" FPI="Forecast Period Indicator"
DATA2DATASTEP LIB TEMP
DATA2DATASTEP LS 256
DATA2DATASTEP MEMLABEL
DATA2DATASTEP MSGTYPE NOTE
DATA2DATASTEP OBS 20
DATA2DATASTEP OUTLIB WORK
DATA2DATASTEP VARLIST TICKER CUSIP STATPERS MEASURE FPI
 
data WORK.IBES_NEW_APPLE;
infile datalines dsd truncover;
input TICKER:$6. CUSIP:$8. STATPERS:DATE9. MEASURE:$6. FPI:$1.;
format STATPERS DATE9.;
label TICKER="IBES Ticker Symbol" CUSIP="CUSIP/SEDOL" STATPERS="I/B/E/S Statistical Period (SAS Format)" MEASURE="Measure" FPI="Forecast Period Indicator";
datalines;
AAPL 03783310 20FEB2020 EPS 6
AAPL 03783310 20FEB2020 EPS 7
AAPL 03783310 20FEB2020 EPS 8
AAPL 03783310 20FEB2020 EPS 9
AAPL 03783310 16JAN2020 EPS 6
AAPL 03783310 16JAN2020 EPS 7
AAPL 03783310 16JAN2020 EPS 8
AAPL 03783310 16JAN2020 EPS 9
AAPL 03783310 19DEC2019 EPS 6
AAPL 03783310 19DEC2019 EPS 7
AAPL 03783310 19DEC2019 EPS 8
AAPL 03783310 19DEC2019 EPS 9
AAPL 03783310 14NOV2019 EPS 6
AAPL 03783310 14NOV2019 EPS 7
AAPL 03783310 14NOV2019 EPS 8
AAPL 03783310 14NOV2019 EPS 9
AAPL 03783310 17OCT2019 EPS 6
AAPL 03783310 17OCT2019 EPS 7
AAPL 03783310 17OCT2019 EPS 8
AAPL 03783310 17OCT2019 EPS 9
;;;;

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

 

ballardw
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 898 views
  • 0 likes
  • 4 in conversation