BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Anandkvn
Lapis Lazuli | Level 10
data dates_format;
input id dates anydtdte32.;
format dates date9. month_year mmyyyy.;
month_year=substr(dates,3);
datalines;
1 10/1/2022
2 23march2023
3 11-feb-2022
;
run;

Hi guys ,

how to get month and year from different date formats 

requiered output:

jan2022

march2023

feb2022

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You have assigned a format that you don't want to use for variable DATES. You don't want it as format DATE9. you want it as format MONYY7.

 

data dates_format;
input id dates anydtdte32.;
format dates monyy7.;
datalines;
1 10/1/2022
2 23march2023
3 11-feb-2022
;
run;

 

--
Paige Miller

View solution in original post

7 REPLIES 7
PeterClemmensen
Super User

Use the MONYY7. Format

 

data dates_format;
input id dates anydtdte32.;
format dates monyy7.;
datalines;
1 10/1/2022
2 23march2023
3 11-feb-2022
;
run;
Anandkvn
Lapis Lazuli | Level 10

Thank you peter

 

for you solution

PaigeMiller
Diamond | Level 26

You have assigned a format that you don't want to use for variable DATES. You don't want it as format DATE9. you want it as format MONYY7.

 

data dates_format;
input id dates anydtdte32.;
format dates monyy7.;
datalines;
1 10/1/2022
2 23march2023
3 11-feb-2022
;
run;

 

--
Paige Miller
Anandkvn
Lapis Lazuli | Level 10

Thank you Miller

if we want extract date and month the which format 

PaigeMiller
Diamond | Level 26

@Anandkvn wrote:

 

if we want extract date and month the which format 


what would it look like?

--
Paige Miller
Anandkvn
Lapis Lazuli | Level 10
data dates_format;
input id dates anydtdte32.; 
format dates date9. dates DATE5.;
datalines;
1 10/1/2022
2 23march2023
3 11-feb-2022
;
run;

 date and month 

PaigeMiller
Diamond | Level 26

@Anandkvn wrote:

 date and month 


I asked "What would it look like?", you haven't shown us what the desired output would look like. Show us.

--
Paige Miller

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 213 views
  • 0 likes
  • 3 in conversation