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);

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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