BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Akshaya_1397
Obsidian | Level 7
Can anyone please help me in how to convert the date 03/01/2022 to 01MAR2022:00:00:00
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Ok, with the explanation for @yabwon you do the conversion in data set A like this

due_date=dhms(due_date,0,0,0);
format due_date datetime19.;

 

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

More information is needed.

 

Is 03/01/2022 in a character variable in a data set? Is it in a numeric variable in a data set? If numeric, what is the format? Is it found in a text file that you have to read into SAS? Is it something else?

--
Paige Miller
Akshaya_1397
Obsidian | Level 7

I have two seprate dates in which 

Dataset A has the variable due_date = 03/01/2022- type-date length-8

Dataset B has the variable due_date = 01MAR2022:00:00:00- TYPE DATE 

 

So I need to change the dates to same format.

Either A-B or B -A

PaigeMiller
Diamond | Level 26

@Akshaya_1397 wrote:

I have two seprate dates in which 

Dataset A has the variable due_date = 03/01/2022- type-date length-8

Dataset B has the variable due_date = 01MAR2022:00:00:00- TYPE DATE 

 

So I need to change the dates to same format.

Either A-B or B -A


In SAS, there is no such thing as type-date, so I don't know what you mean. Nevertheless, you have not answered my questions, so I ask again:

 

Is 03/01/2022 in a character variable in a data set? Is it in a numeric variable in a data set? If numeric, what is the format? Is it found in a text file that you have to read into SAS? (okay, this last one is answered, these are in SAS data sets)

--
Paige Miller
yabwon
Meteorite | Level 14

The origin of the confusion is that the EG, when you hoover over variable name in open dataset, if it recognise numeric variable with date/datetime fomat it displays "date" type.

EG_date.jpg

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

Ok, with the explanation for @yabwon you do the conversion in data set A like this

due_date=dhms(due_date,0,0,0);
format due_date datetime19.;

 

--
Paige Miller
AMSAS
SAS Super FREQ

@Akshaya_1397 Take a look at
Working with Dates in the SAS System that's a good starting place

Dates, Times, and Intervals 


Here's some examples of using SAS Date/Time values

data work.have ;
	date="15APR2023"d ; /* SAS Date Constant */
	put date= date= ddmmyy10. ; /* Output to the SAS log the raw date value and a formated date value */
	datetime="15APR2023 11:59:59"dt ; /* SAS Date Time Constant */
	put datetime= datetime= datetime. ;/* Output to the SAS log the raw datetime value and a formated datetime value */
	cdate=putn(date,"mmddyy8.") ; /* Convert a SAS date value into a character variable using a format (mmddyy8.) */
	put cdate= ;
run ;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 210 views
  • 5 likes
  • 4 in conversation