BookmarkSubscribeRSS Feed
radha009
Quartz | Level 8

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;

 

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

What do you want exactly?

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

radha009
Quartz | Level 8

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

 

 

ChanceTGardener
SAS Employee

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;

 

 

mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 in conversation