Hi,
I am trying to fetch the id's who transacted money on 25thDec2016 only.
id | date | Transaction_Amount |
1 | 25-Dec-16 | 2300 |
2 | 16-May-16 | 3000 |
3 | 1-Jan-16 | 1200 |
4 | 25-Dec-16 | 4000 |
5 | 31-Oct-16 | 9000 |
6 | 25-Sep-16 | 1700 |
7 | 25-Dec-16 | 800 |
8 | 19-Mar-16 | 500 |
9 | 9-Jul-16 | 2000 |
10 | 25-Dec-16 | 1500 |
Please help!!
You can extract the relevant observations like this
data have;
input id $ date :date7. Transaction_Amount;
format date date7.;
datalines;
1 25-Dec-16 2300
2 16-May-16 3000
3 1-Jan-16 1200
4 25-Dec-16 4000
5 31-Oct-16 9000
6 25-Sep-16 1700
7 25-Dec-16 800
8 19-Mar-16 500
9 9-Jul-16 2000
10 25-Dec-16 1500
;
data want;
set have;
where date = '25DEC16'd;
run;
Is that what you want?
How is your data stored? Is date stored as a character or numeric variable?
You can extract the relevant observations like this
data have;
input id $ date :date7. Transaction_Amount;
format date date7.;
datalines;
1 25-Dec-16 2300
2 16-May-16 3000
3 1-Jan-16 1200
4 25-Dec-16 4000
5 31-Oct-16 9000
6 25-Sep-16 1700
7 25-Dec-16 800
8 19-Mar-16 500
9 9-Jul-16 2000
10 25-Dec-16 1500
;
data want;
set have;
where date = '25DEC16'd;
run;
Is that what you want?
If the field is a SAS date, numeric with a date format then you need a date literal.
When hard coding in a date into your code or creating a date, you need to specify it in the DATE9. format, and add a d at the end. For example:
date_var = ’31Jan2016’d;
You aren’t required to put in a 4 year date, but I highly recommend it. Another way to reference a date without using a literal is to use the MDY function. 1,
x = MDY(1, 31, 2016);
With the dates specified in this format you can use it in your code, either assign it to a variable or use it for comparison. The following two lines of code will result in the same thing
if x=’31Jan2016’d then do;
if x=mdy(1, 31, 2016) then do;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.