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

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