BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

 

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

I believe the code i posted does the same, could you check.

Thanks,
Jag

View solution in original post

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

I assume you want to print the date value as they are in the datalines, correct?

BrahmanandaRao
Lapis Lazuli | Level 10

Split the date formats as it is 

In datalines 

Patrick
Opal | Level 21

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.

 

Patrick
Opal | Level 21

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;
BrahmanandaRao
Lapis Lazuli | Level 10

Split as dataset accordingly with date formats 

BrahmanandaRao
Lapis Lazuli | Level 10

Split as different dataset as given date formates

Patrick
Opal | Level 21

@BrahmanandaRao 

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.

BrahmanandaRao
Lapis Lazuli | Level 10

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

Patrick
Opal | Level 21

@BrahmanandaRao 

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. 

BrahmanandaRao
Lapis Lazuli | Level 10

Hi patrick

 

i want output print as below like different  datasets

 

dataset 1dataset 2dataset 3
01-01-1730-Oct-1730/10/19
30-10-1931-Oct-1731/01/16
31-10-1901-Nov-1701/05/16
01-11-1902-Nov-1715/05/16
02-11-1903-Nov-17 
03-11-19  
Jagadishkatam
Amethyst | Level 16

I believe the code i posted does the same, could you check.

Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 12 replies
  • 2883 views
  • 3 likes
  • 4 in conversation