SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Date format Month and Year

Accepted Solution Solved
Reply
Regular Contributor
Posts: 215
Accepted Solution

Date format Month and Year

[ Edited ]

Hi there,

I wanted to extract the Month and Year from the date and soft them by MonthYear.

After running the following code I see that MonthYear in sas dataset (want) is also $7. format. When I export the dataset to excel (os that I can do some manipulation in excel) I see that MonthYear is not in date format. Can someone please help.

 

data want;
set have;
MonthYear=put(Date,monyy7.);
run;


Accepted Solutions
Solution
‎11-12-2015 01:14 PM
Super User
Posts: 17,819

Re: Date format Month and Year

PUT() converts the variable to a character format. Apply the format instead of converting it.

Format MonthYear monyy7.;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,612

Re: Date format Month and Year

[ Edited ]

You haven't actually asked a question. It seems like your sample code would get you the month and year.

 

What is the problem?

 

Now that you have added a paragraph to the original message, I withdraw my questions.

Regular Contributor
Posts: 215

Re: Date format Month and Year

Here it is Miller
Solution
‎11-12-2015 01:14 PM
Super User
Posts: 17,819

Re: Date format Month and Year

PUT() converts the variable to a character format. Apply the format instead of converting it.

Format MonthYear monyy7.;

Super User
Posts: 5,081

Re: Date format Month and Year

Why not make life easy and just create two variables:

 

data want;

set have;

y = year(date);

m = month(date);

run;

 

They will pass to Excel easily, and can easily be sorted in any order you need.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 446 views
  • 2 likes
  • 4 in conversation