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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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