BookmarkSubscribeRSS Feed
somebody
Lapis Lazuli | Level 10

I have a stock dataset. I would like to create 1 extra row, which is the date, after the last date of the stock in the dataset. So for example, my dataset contains prices for stock IBM from 20190102 until 20190630. I want to create 1 extra row for the date 20190701.  One extra requirement is that it cannot be a holiday, i.e. It has to be a business date.

I have a dataset called TRADINGDAYS that has 1 column of dates that are business dates. it looks like this. The dataset is attached

Begin 
20190102
20190103
......
20191230

 

 

 

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

The easy part can be solved like this.

 

Post your tradingdays data if you want that included as well

 

data want;
   do until (last.stock);
      set sashelp.stocks;
      by stock;
      output;
   end;
   date + 1;
   output;
run;
somebody
Lapis Lazuli | Level 10

Thanks. I edited my question and attached the tradingdays dataset. can you please have a look and incorporate that ?

PeterClemmensen
Tourmaline | Level 20

Ok, just needed the structure. Here, I created a very simple replica of your tradingdays data set. It is just the day after the last date for each atock in sashelp.stocks. 

 

See if it works for you

 

data tradingdays;
input begin :ddmmyy10.;
format begin ddmmyy10.;
datalines;
02/08/1986
run;


data want(drop=begin);

   dcl hash h(dataset : "tradingdays(rename=begin=date)");
   h.definekey("date");
   h.definedone();

   do until (last.stock);
      set sashelp.stocks;
      by stock;
      output;
   end;

   do until (h.check());
      date + 1;
   end;
   
   output;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1768 views
  • 0 likes
  • 2 in conversation