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
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
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'?
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.
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;
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)
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 ;
@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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.