Desktop productivity for business analysts and programmers

SAS Date format - want to have only month

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

SAS Date format - want to have only month

Gurus -

I want to pull only the month from the datasets. Currently the date is stored as example 12Aug2012. I just need Aug.

Thanks in advance.


Accepted Solutions
Solution
‎09-06-2012 05:39 PM
Grand Advisor
Posts: 10,211

Re: SAS Date format - want to have only month

Is the value a SAS date, i.e. numeric with a default format of Date9. or is it string?

If a SAS date then you can change the format Monname3. and it will display as Aug.

If need to select a specific month (not including year) of data you can use

if month(datevariablename) = 8; or the number of the month you want if the variable is a SAS date.

View solution in original post


All Replies
Solution
‎09-06-2012 05:39 PM
Grand Advisor
Posts: 10,211

Re: SAS Date format - want to have only month

Is the value a SAS date, i.e. numeric with a default format of Date9. or is it string?

If a SAS date then you can change the format Monname3. and it will display as Aug.

If need to select a specific month (not including year) of data you can use

if month(datevariablename) = 8; or the number of the month you want if the variable is a SAS date.

Contributor
Posts: 29

Re: SAS Date format - want to have only month

Hi Ballarw -

If we are using proc sql example Select Month(xxxdate) gives me numeric "8", do you know how to change it to display "Aug".

Thanks


Respected Advisor
Posts: 4,608

Re: SAS Date format - want to have only month

You can use

select month(xxxdate) as month format=NLSTRMON3.1, ...

this works for locale=English_UnitedStates, for other locales you must adjust the field width. For example, for locale=French_Canada, you must use NLSTRMON5.1 .

PG

PG
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 276 views
  • 0 likes
  • 3 in conversation