BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Elliott
Obsidian | Level 7

Hello,

 

I have a date in a character field that looks like 2017JAN and I need to convert to 201701 in another field, so it is recognized as a date.  I have tried everything I can think of and researched but can not get the conversion to work.

 

Any assistance will be greatly appreciated.

 

Elliott

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data x;
x='2017JAN';
y=input(cats(substr(x,5),substr(x,1,4)),monyy7.);
format y yymmn6.;
run;
proc print;run;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

In SAS, 201701 is not a date.  The conversion can be made as you requested, but you are not getting a date as the result.  Here is one way to go about it.  It gets your six-digits as a numeric value:

 

newvar = input(oldvar, 4.) * 100 + month(input('01' || substr(oldvar, 5, 3) || substr(oldvar, 1, 4), date9.);

Ksharp
Super User
data x;
x='2017JAN';
y=input(cats(substr(x,5),substr(x,1,4)),monyy7.);
format y yymmn6.;
run;
proc print;run;

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