BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anilatikkha310
Fluorite | Level 6

Hi,

 

I am trying to fetch the id's who transacted money on 25thDec2016 only.

 

id dateTransaction_Amount
125-Dec-162300
216-May-163000
31-Jan-161200
425-Dec-164000
531-Oct-169000
625-Sep-161700
725-Dec-16800
819-Mar-16500
99-Jul-162000
1025-Dec-161500

 

Please help!!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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?

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

How is your data stored? Is date stored as a character or numeric variable?

anilatikkha310
Fluorite | Level 6
The date is stored in numeric format.
##- Please type your reply above this line. Simple formatting, no
attachments. -##
PeterClemmensen
Tourmaline | Level 20

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?

Reeza
Super User

If the field is a SAS date, numeric with a date format then you need a date literal.

 

Date Literal (d)

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;

anilatikkha310
Fluorite | Level 6
Thanks for explaining the above cases it is really informative.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 5912 views
  • 3 likes
  • 3 in conversation