Help using Base SAS procedures

converting character date to numeric date

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

converting character date to numeric date

Hi all,

My SAS dataset named france has a variable Base_Date(Lenth:12, Format:$12, Informat:$12. Tpye: character). The obs. displayed like "2-Feb-06".

The attributes of Base_Date in other datasets are Lenth: 8 Format: DATE9.  InformatSmiley Very HappyATE9.  Tpye: numeric and I want to convert the character date to numeric date just like the above.

My commands are as follows:

data france;

set france;

Base_Date=input(Base_Date,date9.);

run;

*failure, obs. like "2-Feb-06" becomes "16834";

*Lenth: 12 Format: $12. Informat: $12. Tpye: character remain the same;

I also tried some commands like below:

data france;

set france;

Base_Date=input(Base_Date,yymmdd8.);

run;

*failure, all obs. of this variable become missing values;


Could anyone give me some suggestions? Also I want to know why the attributes of Base_Date in a dataset are different from that in other datasets given that I import the data from the same type of file (CSV) to SAS using the same commands.

Thanks.


Accepted Solutions
Solution
‎06-20-2012 02:02 AM
Super User
Posts: 9,687

Re: converting character date to numeric date

You need a format.

data france;

set france;

new_Base_Date=input(Base_Date,date9.);

format new_Base_Date date9. ;

run;

View solution in original post


All Replies
Solution
‎06-20-2012 02:02 AM
Super User
Posts: 9,687

Re: converting character date to numeric date

You need a format.

data france;

set france;

new_Base_Date=input(Base_Date,date9.);

format new_Base_Date date9. ;

run;

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 1825 views
  • 0 likes
  • 2 in conversation