BookmarkSubscribeRSS Feed
raja777pharma
Fluorite | Level 6

Hi ,

I am converting the character date to numeric, but only year and month values are not populating , i am using below code but getting error as "yymmd.) format not find.

 

raja777pharma_1-1733816916370.png

 

raja777pharma_0-1733816746956.png

 

Can any one suggest how to populate only year and month values.

 

Thank you,

Raja.

 

3 REPLIES 3
Ksharp
Super User
 
data have;
input x $20.;
y=input(x,anydtdte32.);
format y yymmdd10.;
cards;
2020-10-10
2022-08
;

 

Ksharp_0-1733817930928.png

 

PaigeMiller
Diamond | Level 26

@raja777pharma wrote:

 

Can any one suggest how to populate only year and month values.


You want to take the first 7 characters of dtc_ and ignore the rest. You will also need to remove the hyphen from these dates.

 

dtc1_=compress(substr(dtc_,1,7),'-');
dt=input(dtc1_,yymmn6.);
format dt yymm6.; /* or any other format you want */

 

There is no informat YYMMD which is why you get the error. There is an informat YYMMDD (with two Ds on the end), but that won't work on the data in DTC_ that you show.

 

You might want to talk to whomever provides you with dates as character strings that this is not a good thing to do. Or if you converted the dates to character strings earlier in the program, don't do that. Keep dates as numeric variables.

 

Please do not provide the log as a screen capture. Please provide the log by copying it as text and then pasting it into the window that appears when you click on the </> icon.

PaigeMiller_0-1715196634946.png

--
Paige Miller
Kurt_Bremser
Super User
You must create a day for such partial values. So you need a rule for that which makes sense in your business context, e.g. the first, the last, or the 15th of the month. Once you have the rule, you can put it in code.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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