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

Hi,

 

My input data 2016- Jan (Charactor) I need output only month like 01(Numaric) in DI studio. 

 

Ex:   2016- Jan -------> 01

        2016- Feb-------->02

 

Please help me on my request. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data want;
input date_char $;
date = input(scan(date_char,2,'-')!!scan(date_char,1,'-'),anydtdte8.);
format date date9.;
month = month(date);
cards;
2016-Jan
;
run;

do this in User Written Code

View solution in original post

6 REPLIES 6
LinusH
Tourmaline | Level 20

Use the input() function, together with an appropriate date informat (see the Base SAS documentation).

Data never sleeps
chirumalla
Calcite | Level 5

Yes, I have used Input() function but I couldn't able to get exact informat, please help me on informat.

LinusH
Tourmaline | Level 20

What have you tried?

And talking about "exact". Thre's a space between the hyphen and the month name. You need to get rid of that first (compress()).

Data never sleeps
chirumalla
Calcite | Level 5

Their is no space between hypen and month (2016-Jan). I tried most of informats. 

Kurt_Bremser
Super User
data want;
input date_char $;
date = input(scan(date_char,2,'-')!!scan(date_char,1,'-'),anydtdte8.);
format date date9.;
month = month(date);
cards;
2016-Jan
;
run;

do this in User Written Code

chirumalla
Calcite | Level 5

Hi 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1281 views
  • 0 likes
  • 3 in conversation