SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Character to numeric convertion

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Character to numeric convertion

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. 


Accepted Solutions
Solution
‎10-18-2016 07:41 AM
Super User
Posts: 6,936

Re: Character to numeric convertion

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 5,256

Re: Character to numeric convertion

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

Data never sleeps
Contributor
Posts: 41

Re: Character to numeric convertion

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

Super User
Posts: 5,256

Re: Character to numeric convertion

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
Contributor
Posts: 41

Re: Character to numeric convertion

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

Solution
‎10-18-2016 07:41 AM
Super User
Posts: 6,936

Re: Character to numeric convertion

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 41

Re: Character to numeric convertion

Hi 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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