3 users online | 3 Guests and 0 Registered

Is there a way in SAS to read in Excel Long Dates?


SAS is well-equipped with a number of INFORMATs which allow the source data to be read in.  There is a particularly useful date informat called ANYDTDTEw. which reads a wide range of date styles, however it cannot cope with one of Excles Long Date formats in the style: Friday, 28 July 2023.

One solution for this is to wrrite a user-defined function, which can then be used to transform a text string.

This can be seen here:

 data longdate ;
   infile datalines dsd ;
   input ld :$40. ;
datalines ;
"Friday, 28 July 2023"
;
run ;

options cmplib = work.functions ;

proc fcmp outlib = work.functions.func ;
  function worddate(wd $) ;
    newdt = input(cats(scan(wd,-3),substr(scan(wd,-2),1,3),scan(wd,-1)),date9.) ;
  return(newdt) ;
  endsub ;
run ;

data longdate ;
  set longdate ;
    datevar = worddate(ld) ;
    format datevar ddmmyy10. ;
 run ;
Author:
Alan D Rudland
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.