DATA Step, Macro, Functions and more

Extract data from the dataset for next 5 days

Reply
Contributor
Posts: 70

Extract data from the dataset for next 5 days

i have a dataset with one month data. i want to have another dataset with only next 5 days of data. dataset have variables ID, summary, poc, start date,support..

 

I want the next 5 days of start date dataset. - Thank you for your help.

 

proc sql;
create table Task.test as
select * from task.deploy_file as A where Scheduled_Start_Date <= (Scheduled_Start_Date +5);
quit;

 

 

PROC Star
Posts: 2,374

Re: Extract data from the dataset for next 5 days

What do you want exactly?

Your test is always true:  A  <= A+5  is of course true

Contributor
Posts: 70

Re: Extract data from the dataset for next 5 days

yes, it is giving all records . I have a table with other variables and date field from today date until next one month (06-27-2018 to 07-27-2018). I am tyring to create a dataset  with only records from today date to next 5 days (06-27-2018 to 07-01-2018).

 

 

SAS Employee
Posts: 7

Re: Extract data from the dataset for next 5 days

There are probably simpler solutions if you only need to do this once, but I run into this same issue all the time (except in the opposite direction... I usually need today and the last n days), so I wrote a small macro to reference repeatedly. The only catch: the daylag parameter uses positive numbers to reference previous days (e.g. daylag=1 corresponds to yesterday's date), so if you want to reference future days, the number will be negative (e.g. daylag=-1 will be tomorrow's date). 

 

data have;
input date date9. var1;
datalines;
27JUN2018 53.5
28JUN2018 58.7
29JUN2018 41.8
30JUN2018 21.6
01JUL2018 17.6
02JUL2018 18.8
03JUL2018 17.7
04JUL2018 19.9
05JUL2018 27.7
06JUL2018 25.5
07JUL2018 26.9
;
run;

%macro day(daylag=0,format=DATE9.);
%local daystring;
%let daystring=%sysfunc(putn(%sysfunc(intnx(day,"%sysfunc(today(),DATE9.)"d,-(&daylag))),&format.));
&daystring
%mend;


data work.want;
set work.have;
where "%day(daylag=0)"d<=date<="%day(daylag=-4)"d;
format date DATE9.;
run;

proc print data=work.want; run;

 

 

Trusted Advisor
Posts: 1,346

Re: Extract data from the dataset for next 5 days

So you want all tasks scheduled up to 5 days after the current date (i.e. the date the program is running).  If so, you can use the TODAY() function,  Using our proc sql code:

 

proc sql;
  create table Task.test as
  select * from task.deploy_file as A where Scheduled_Start_Date <= (today() +5);
quit;

 

Or if the source table has historical tasks, use

proc sql;
create table Task.test as
select * from task.deploy_file as A where Scheduled_Start_Date  between today() and (today()+5;
quit;
Ask a Question
Discussion stats
  • 4 replies
  • 80 views
  • 0 likes
  • 4 in conversation