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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 641 views
  • 0 likes
  • 3 in conversation