Hi Experts
GoodMorning
here i have a dataset
how to print different date formats
i want ouput print datastep and proc step
data ds;
infile datalines;
input date anydtdte.;
format date date9.;
datalines;
01-01-17
30-10-19
31-10-19
01-11-19
02-11-19
03-11-19
30-Oct-17
31-Oct-17
1-Nov-17
2-Nov-17
3-Nov-17
30-10-19
31/01/16
01/05/16
15/05/16
;
run;
I believe the code i posted does the same, could you check.
I assume you want to print the date value as they are in the datalines, correct?
Split the date formats as it is
In datalines
SAS Date formats allow you to define how a SAS data value gets printed. You can either assign such a format permanently to a SAS variable, ie. via a Format statement, or you can define the format directly in many procedures.
Docu here
data ds;
infile datalines;
input date anydtdte.;
format date ddmmyyd10.;
datalines;
01-01-17
30-10-19
31-10-19
01-11-19
02-11-19
03-11-19
30-Oct-17
31-Oct-17
1-Nov-17
2-Nov-17
3-Nov-17
30-10-19
31/01/16
01/05/16
15/05/16
;
run;
proc print;
run;
Split as dataset accordingly with date formats
Split as different dataset as given date formates
Please explain in more detail or even better show us how the desired result based on your sample data should look like. Your "twitter feeds" leave too much open.
Here 15 dates in different formats
So i want those date formats split into according date formates
As per given data 15 dates each date format
Print as one dataset
The data step you've posted uses informat anydtdte. to convert the source strings into SAS Date values. This appears to work.
You then apply a SAS Format to print these SAS Date values (a count of days since 1/1/1960) in a human readable form.
SAS format ddmmyyd10. prints SAS Date values in the form dd-mm-yyyy
That's my answer to how I understand your question with the code already provided previously. If you need anything else then please explain better or show us the desired result based on the data you've already posted.
Hi patrick
i want output print as below like different datasets
dataset 1 | dataset 2 | dataset 3 |
01-01-17 | 30-Oct-17 | 30/10/19 |
30-10-19 | 31-Oct-17 | 31/01/16 |
31-10-19 | 01-Nov-17 | 01/05/16 |
01-11-19 | 02-Nov-17 | 15/05/16 |
02-11-19 | 03-Nov-17 | |
03-11-19 |
I believe the code i posted does the same, could you check.
please try
data date1 date2 date3;
infile datalines;
input date $10.;
if prxmatch('m/\d{2,2}\-\d{2,2}\-\d{2,2}/oi',date) then output date1;
else if prxmatch('m/\w[a-z]+/oi',strip(date)) then output date2;
else if prxmatch('m/\d{2,2}\/\d{2,2}\/\d{2,2}/oi',date) then output date3;
datalines;
01-01-17
30-10-19
31-10-19
01-11-19
02-11-19
03-11-19
30-Oct-17
31-Oct-17
1-Nov-17
2-Nov-17
3-Nov-17
30-10-19
31/01/16
01/05/16
15/05/16
;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.