BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I've x=20090801 ( as $8 char)

I want to calculate y = month(x), so that y = 08.

But if i use it like this it gives me . (missing values).

Please sugest.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Recommended SAS DOC reading on Dates and using INPUT function to convert from characters and using MONTH function. Google advanced search argument:

using sas date variables site:sas.com

Scott Barry
SBBWorks, Inc.
barheat
Fluorite | Level 6
You have x as a character string for date with a yymmddn8. format.
The simplest method is to use a simple substring:
month = substr(x,5,2);
This create month as a string. If you want month as a numeric:
month = input(substr(x,5,2),2.);

If you want to use the month function you need to first convert the string to a SAS date.
date = input(x,yymmdd8.);
y = month(date);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1168 views
  • 0 likes
  • 3 in conversation