Hello,
I am looking for information on how to use a WHERE statement in a PROC PRINT to specify a date. For example I want to show all observations where data equal to 1 Jan 2000.
Regards,
P.
hi,
proc print data = your_data;
where date = mdy(01,01,2000);
var var_list;
run;
Best of luck,
Anca.
hi,
proc print data = your_data;
where date = mdy(01,01,2000);
var var_list;
run;
Best of luck,
Anca.
Hi Anca,
Thanks for that. Is it possible to use the same function to return all observations from January 2000, regardless of the day?
Regards,
P.
print data=have;
where date between mdy(1,1,2000) and mdy(1,31,2000);
run;
or:
data have;
input date mmddyy10.;
format date mmddyy10.;
cards;
01/31/2000
01/02/2000
02/04/2000
;
proc print data=have;
where date between intnx('month','01jan2000'd,0,'b') and intnx('month','01jan2000'd,0,'e') ;
run;
where date = '01jan2000'd;
Notice the d at the end and the quotations around the date. The quotations can be single or double and the year can be two or four digit.
Hi Reeza,
What is the d at the end for? Also how would SAS know the date format (e.g.: dd/mm/yy, mm/dd/yy, dd/mm/yyyy, etc) and would it be possible to specify only the month and the year?
Regards,
P.
SAS stores dates as numbers, the format is only used to display the numbers so when you specify the 'd' it tells SAS it's a date and it converts it into a number.
You can also specify a between with the literals:
where date between '01jan2000'd and '31jan2000'd but then you have to know the start and end of the month.
LinLin's solution above is better for that.
You could also specify the month and year separately
where month(date)=1 and year(date)=2000;
@pmdci
The SAS date literal requires the date to be in a DATE informat. Other date informats are not supported. The following will work (not an exhaustive list):
'01jan80'd
'01jan1980'd
'01-jan-1980'd
You could use the INTCK function :
print data=have;
where intck('month', '1jan2000'd, date) = 0 ;
run;
Richard
As you can see, SAS is very resourceful when dealing with date variable, the following two options should work for you as well:
where month(date)=1 and year(date)=2000;
where put(date,monyy7.)='JAN2000';
Haikuo
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.