Help using Base SAS procedures

Character to SAS Date Conversion??

Reply
Occasional Contributor
Posts: 8

Character to SAS Date Conversion??

I want to convert character date "JUL 2010" to Sas date value in EURDFDMY7(MMMYYYY) format.

I have done the sub setting

data test.datechar1;
set test.datechar1;
length month $3 year $4;
month=substr (date,1,3);
year=substr (date,5,4);
run;

and concantenated to remove the space between JUL and 2010.

INPUT function does not seems to work for the EURDFDMY7 format in SAS version 8.

Can anyone suggest me any other method to convert character date to sas date in EURDFDMY7 format (MMMYYYY) like JUL2010 .
Occasional Contributor
Posts: 9

Re: Character to SAS Date Conversion??

*---> create format to convert 3 char month to number.;
data temp(keep=start label fmtname);
retain fmtname "$month2number";
start = 'JAN'; label=1; output;
start = 'FEB'; label=2 output;
start = 'MAR'; label=3; output;
start = 'APR'; label=4; output;
...etc...
run;
*---> create a temporary format;
proc format cntlin=temp;
run;

data test.datechar1;
set test.datechar1;
length month $3 year $4;
month=substr (date,1,3);
year=substr (date,5,4);
*---> convert the month to a number.;
monthn = put(month,$month2number.);
*---> create a SAS date as though it is the first day of the month.;
sasdateout = mdy(monthn,1,year);
attrib sasdateout length=8 format=EURDFDMY7.;
run;
Frequent Contributor
Posts: 120

Re: Character to SAS Date Conversion??

Are you using the correct format?

This works, but may not be what you ask for....

data _null_;
a = today();
put a EURDFMY7.;
b = 'jun 2010';
c = input(compress(b),EURDFMY7.);
put c yymmdd10.;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 634 views
  • 0 likes
  • 3 in conversation