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

Hello,

 

I have a data like:

date = 20200124 the format is NUM 8 YYMMDDN8.

I am trying to convert the date's type as CHAR 8. as requested. 

I am using 

new_date = put(date yymmdddn8.)

;

It shows 21938 

Is that anyway can show the new_date as 20200124?

 

Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your format has too many d's. It needs two not three ds.

 

 

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

You missed a comma and you used an invalid format name.

new_date = put(date, yymmddn8.)
jhusoc
Obsidian | Level 7
Sorry. I used comma in my code. However, the output is still 21938 NOT 20200124. Is there any way can show the output as 20200124? Thank you!
PaigeMiller
Diamond | Level 26

Works for me.

 

data have;
    date='24JAN2020'd;
    format date yymmddn8.;
run;
data want;
    set have;
    new_date=put(date,yymmddn8.);
run;
--
Paige Miller
jhusoc
Obsidian | Level 7
I think the reason is I did the calculation first, then the SAS give me the sysdate like: 21938. I formated the 21938 to 20200124. It may still 21938 in system. IS there a way can change from 21938 to 20200124 as char type? Thank you!
jhusoc
Obsidian | Level 7

It should : 

new_date = put(date, yymmdddn8.);
Reeza
Super User

Your format has too many d's. It needs two not three ds.

 

 

jhusoc
Obsidian | Level 7
Thank you!

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