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

I'm trying to chain format changes to go from a date in Date9. format to a character variable which will be the year-month variable of the same date. For example, starting from 05OCT2017 (date type), I want to end up with 201710.

 

I don't want do this with intermediary data steps and I want to do it in PROC SQL while avoiding subqueries as well.

It seemed natural to try the following, but this syntax isn't valid. How do I do this?

Create table want as
Select put(purchase_date format=YYMMN6., YYMMN6.)
  From have
;

 

1 ACCEPTED SOLUTION
3 REPLIES 3
Autotelic
Obsidian | Level 7
Even though I don't understand it, it works.
I thought the second parameter in the put() function should be how one wants to read the first parameter, but the first parameter is Date9., so, in my mind, trying to read Date9. as YYMMN6. should yield a missing value.
Kurt_Bremser
Super User

@Autotelic wrote:
Even though I don't understand it, it works.
I thought the second parameter in the put() function should be how one wants to read the first parameter, but the first parameter is Date9., so, in my mind, trying to read Date9. as YYMMN6. should yield a missing value.

You're confusing the put() and the input() function. input() reads, while put() displays. Therefore you also need display formats for put(), but informats for input().

In your case, the date value in the original variable purchase_date is "displayed" in the yymmn6. format, and the resulting character string stored in the new variable which is also named purchase_date.

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
  • 3 replies
  • 1224 views
  • 2 likes
  • 2 in conversation