BookmarkSubscribeRSS Feed
dangoebel
Calcite | Level 5

I have an equation that regresses the current front month price of a commodity against each subsequent month after that (i.e. Oct = Nov, Oct = Dec, Oct=Jan15 ect.) My current equations looks like this

'11/15/14'n:model lncornY0M10 = lncornY0M11/noprint;

'12/15/14'n:model lncornY0M10 = lncornY0M12/noprint;

'01/15/15'n:model lncornY0M10 = lncornY1M01/noprint;

'02/15/15'n:model lncornY0M10 = lncornY1M02/noprint;

'03/15/15'n:model lncornY0M10 = lncornY1M03/noprint;

'04/15/15'n:model lncornY0M10 = lncornY1M04/noprint;

'05/15/15'n:model lncornY0M10 = lncornY1M05/noprint;

'06/15/15'n:model lncornY0M10 = lncornY1M06/noprint;

'07/15/15'n:model lncornY0M10 = lncornY1M07/noprint;

'08/15/15'n:model lncornY0M10 = lncornY1M08/noprint;

'09/15/15'n:model lncornY0M10 = lncornY1M09/noprint;

'10/15/15'n:model lncornY0M10 = lncornY1M10/noprint;

'11/15/15'n:model lncornY0M10 = lncornY1M11/noprint;

'12/15/15'n:model lncornY0M10 = lncornY1M12/noprint;

'01/15/15'n:model lncornY0M10 = lncornY2M01/noprint;

'03/15/15'n:model lncornY0M10 = lncornY2M03/noprint;

'04/15/15'n:model lncornY0M10 = lncornY2M04/noprint;

'05/15/15'n:model lncornY0M10 = lncornY2M05/noprint;

'06/15/15'n:model lncornY0M10 = lncornY2M06/noprint;

'07/15/15'n:model lncornY0M10 = lncornY2M07/noprint;

With lncornY0M10 being the natural log of the daily change in corn for the current year, 10th month (October). I was wondering if it would be possible to write a macro that could replace the dependent variable with the current front month when the data switches months. Said differently, Is there an easy way to have the dependent variable switch from lncornY0M10 on october 31st to lncornY0M11 on November 1st? Also, On January 1st the dependent variable will become lncornY0M01 instead of lncornY1M01.

Thanks!

4 REPLIES 4
jakarman
Barite | Level 11

Use a dedicated variable simulation date as origin.

When not set the value should be set with the system date.

With this you can simulate time travelling and the macro can be developed and tested.

Using the real system date makes this process impossible. Just good coding practice to have it verifiable allowing alternate dates.

The best thing having it as global standard

---->-- ja karman --<-----
dangoebel
Calcite | Level 5

I'm able to pull in past datasets to be able to change the current front month. The issue is developing a macro that accomplishes that.

ballardw
Super User

WHAT is the rule for Y2 vs Y1 vs Y0? Does your data have any actual dates involved? The values of date variables if containing the correct information could be used to determine start and end dates available and likely create needed code but a description of your base data is needed for that approach.

dangoebel
Calcite | Level 5

variables are automatically created nightly from futures exchange prices from the previous day. The system we have then takes those prices and arranges them in the Y#M## format. If the current month is october the data will come in ending in Y0M10. If you wanted to look at the price in June of 2016 youd look for the variable ending in Y2M06. I have 90 days worth of price history to run a regression off of with the most current date coming in as 15OCT14. So I guess it would be possible to link the current month to the most recent date being pulled in. An example of my data is below (note that this is from a data set on September 22nd so in this example Y0M09 is the most current month) The date variable ends with 22SEP14.

sas data example.jpg

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 788 views
  • 0 likes
  • 3 in conversation