BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ndamo
Obsidian | Level 7

Dear Communities , 

 

I am challenged with the Date format . 

So what should I do to get the same format as Date 1 and Date 2 for Date 3?

 

Date name  DateChar
Date 1 22AUG2023
Date 2 06SEP2023
Date 3 29/SEP/2023

 

Here is my program : 

DateChar=INPUT(DateChar,DATE9.) ;
FORMAT DateChar DATE9. ;

 

Thank you in advanced 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You cannot store a NUMBER into a character variable.

You need to use a large enough WIDTH on the INFORMAT to read ALL of the relevant characters from the source string.

 

To leave the variable has character use the PUT() function.

DateChar=put(input(DateChar,date11.),date9.) ;

To store the value as an actual DATE you will need to make a NEW variable.

DateNum=input(DateChar,date11.);
format DateNum date9.;

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

DATE9. won't work because the third date has more than 9 characters.

 

Have you tried DATE11.  ??

--
Paige Miller
ndamo
Obsidian | Level 7

Yes , it did not work. Indeed , I have two column  DateChar and DateNum . For DateNum everything Ok , I have only issue in DateChar and I have to keep this column .

PaigeMiller
Diamond | Level 26

@ndamo wrote:

Yes , it did not work. Indeed , I have two column  DateChar and DateNum . For DateNum everything Ok , I have only issue in DateChar and I have to keep this column .


Please from now on never say "it did not work" and then you don't show us your code. We can't help you if you don't show us your code, as without your code no one can understand this message.

--
Paige Miller
ndamo
Obsidian | Level 7

As I mentioned in begining, in my inital raw data , I have and the length of Date is $20. :

 

Date name  Date
Date 1 22AUG2023
Date 2 06SEP2023
Date 3 29/SEP/2023

 

Then in my program : 

DateChar=INPUT(DateChar,DATE9.) ;
FORMAT DateChar DATE9. ;

 

After runing this  pgm, two columns created : 

 

Date Name DateChar DateNum
Date 1 22AUG2023 22AUG2023
Date 2 06SEP2023 06SEP2023
Date 3 29/SEP/2023 29SEP2020
Date 4   .

 

In DateNum everything Ok however in DateChar , something wrong . It concerns only Date 3  or Date 4 . 

 

 

PaigeMiller
Diamond | Level 26

You need to try the informat DATE11.

 

datenum=input(datechar,date11.);


Additional comment: from now on, when we ask to see your code, show us the ENTIRE data step, not just one or two lines.

--
Paige Miller
ndamo
Obsidian | Level 7

Thank you , for DateNum is Ok . and How should I do to remove the slash in DateChar?

 

I would like to perform something like  : 

IF Date Name = Date 3 , DateChar=DDMMMYYYY. 

My expected result is => : 

Date Name DateChar DateNum
Date 1 22AUG2023 22AUG2023
Date 2 06SEP2023 06SEP2023
Date 3 29SEP2023 29SEP2020
Tom
Super User Tom
Super User

You cannot store a NUMBER into a character variable.

You need to use a large enough WIDTH on the INFORMAT to read ALL of the relevant characters from the source string.

 

To leave the variable has character use the PUT() function.

DateChar=put(input(DateChar,date11.),date9.) ;

To store the value as an actual DATE you will need to make a NEW variable.

DateNum=input(DateChar,date11.);
format DateNum date9.;
ndamo
Obsidian | Level 7

Thank  you .  The issue is resolved with the PUT fonction .😊

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 1327 views
  • 0 likes
  • 3 in conversation