Hi,
I have a folder which contains daily trading data for each trading day.
These daily data are named based on their corresponding trading days. (e.g. 20171201.sas7bat)
I am trying to get a new data set which combine 5 consecutive daily trading data according to a specified signal date.
What I did is firstly to get next 4 weekdays starting from signal date, then to set these data set together in data step.
But the problem is that some weekdays are actually holidays, so no trading on these days.
In this case, what I get maybe a data set with only 4-day trading data.
Any ideas to correct this?
Thank you very much:)
Your datasets are not named 20171201, that is not valid, needs to start with an _ or letter.
What you can do is, using the sashelp.vtables sort that descending, then take first 5 obs, e.g.:
proc sort data=sashelp.vtable out=inter; by memname; where libname="YOURLIB"; run; data inter; set inter; length klist $2000;
retain klist; if _n_ le 5 then klist=catx(" ",klist,memname); if _n_=5 then call syputx('klist',klist); run; data want; set &klist.; run;
So order the data to get latest 5 files first, then use a retained list of datasets up to 5, and on 5 create macro variable to use in the set statement.
Your datasets are not named 20171201, that is not valid, needs to start with an _ or letter.
What you can do is, using the sashelp.vtables sort that descending, then take first 5 obs, e.g.:
proc sort data=sashelp.vtable out=inter; by memname; where libname="YOURLIB"; run; data inter; set inter; length klist $2000;
retain klist; if _n_ le 5 then klist=catx(" ",klist,memname); if _n_=5 then call syputx('klist',klist); run; data want; set &klist.; run;
So order the data to get latest 5 files first, then use a retained list of datasets up to 5, and on 5 create macro variable to use in the set statement.
Have you tried it in R ?
I am not sure why I would need to?
R handles data.frames.
You should post a R solution for the OP's initial question to illustrate your hint.
It works on my computer.
@Gunther wrote:
It works on my computer.
Don't brag, show the code.
Ok.
Yes, my code should still work. Try it and see if you have further comments.
I think @RW9 is using a good set of tools. But some changes would be required to let you specify a signal date. For example:
%macro five_days (signal_date=);
proc sort data=sashelp.vtable (keep=memname libname) out=inter;
by descending memname;
where libname="YOURLIB" and memname <= "t&signal_date";
run;
* then add the remaining code;
%mend five_days;
%five_days (signal_date=20171204)
Great!
Thanks a lot!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.