BookmarkSubscribeRSS Feed
ganeshsas764
Obsidian | Level 7

hi ,

this isate ganesh, i have one doubt ,

 

id     name    date

101  xxx      19/05/15

102 YYY      19/06/16

103 zzz       19/05/15

 

i want '19/05/15' date values  into output dataset ,how to solve this probleam .

 

Regards

A.Ganesh

11 REPLIES 11
ganeshsas764
Obsidian | Level 7

hi ,

this is ganesh, i have one doubt ,

 

id     name    date

101  xxx      19/05/15

102 YYY      19/06/16

103 zzz       19/05/15

 

i want '19/05/15' date values only  into output dataset ,how to solve this probleam .

 

Regards

A.Ganesh

SAS-questioner
Obsidian | Level 7

When you said you want  '19/05/15' date values only  into output dataset, do you mean make all other dates become '19/05/15', or you want to delete other dates but '19/05/15'?

LinusH
Tourmaline | Level 20

Please elaborate.

Is the example data from an external file?

And you wish to store it in a SAS data set (output)?

Use an informat to translate the date into a SAS date numerical variable.

Data never sleeps
ganeshsas764
Obsidian | Level 7
that values are stored in sas dataset,how to subset particular date values

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Is date a numeric variable or character.  Depending on that you could use where clause or if etc.

data want;
  set have;
  where date="19/05/15";
run;

or 

data want;
  set have;
  where date=input("19/05/15",ddmmyy8.);
run;
ganeshsas764
Obsidian | Level 7
tq

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Reeza
Super User

If you have a SAS date you can use the following to filter.

 

You can specify a date constant in SAS using the date9 format and with a d after the date.

 

"05Sep2015"d

Or you can use the MDY function to create a SAS date

 

mdy(5, 19, 15)

 

ogustavo
Calcite | Level 5

Use quotations followed by d (if using only date - dt, if you're using datetime), and write the date case as "19May15"d (it won't work with "19/05/15"d):

 

/* ===================================== */
/* Date */

DATA subset_by_date;
	INPUT id name $ date;
	INFORMAT date ddmmyy8.;
	FORMAT date ddmmyy8.;
	DATALINES;
101 xxx 19/05/15
102 YYY 19/06/16
103 zzz 19/05/15
;
RUN;

DATA works;
	SET subset_by_date;
	WHERE date = '19May15'd;
RUN;
* Returns only ids 101 and 103;

DATA works_too;
	SET subset_by_date;
	WHERE '18MAY15'D < date < '20May15'd;
RUN;
* Returns only ids 101 and 103;

DATA wont_work;
	SET subset_by_date;
	WHERE date = '19/05/15'd;
RUN;
* ERROR: Invalid date/time/datetime constant '19/05/15'd. ;

/* ===================================== */
/* Datetime */

DATA subset_by_datetime;
	INPUT id name $ datetime;
	INFORMAT datetime anydtdtm40.;
	FORMAT datetime datetime.;
	DATALINES;
101 xxx 19/05/15
102 YYY 19/06/16
103 zzz 19/05/15
;
RUN;

DATA works_datetime;
	SET subset_by_datetime;
	WHERE datetime = '16Jun19:00:00:00'dt;
RUN;
* Returns only id 102 ;
Reeza
Super User

@SAS-questioner @ogustavo This is a 5 year old thread, if you have a question it may be best to post it as a new post not on top of this one. Only users who initially responded to this post will see any updates/responses.

 

ogustavo
Calcite | Level 5
@Reeza What I posted is a possible solution to the OP's issue, is it not? Where is the proper place for that?
Reeza
Super User
I'm not sure of the value of answering a 5+ year old question but that is your prerogative.

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
  • 11 replies
  • 6755 views
  • 0 likes
  • 6 in conversation