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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 4850 views
  • 3 likes
  • 3 in conversation