BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
PUT() converts the variable to a character format. Apply the format instead of converting it.

Format MonthYear monyy7.;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
mlogan
Lapis Lazuli | Level 10
Here it is Miller
Reeza
Super User
PUT() converts the variable to a character format. Apply the format instead of converting it.

Format MonthYear monyy7.;

Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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