Warm tip: This article is reproduced from stackoverflow.com, please click
date sas

how to convert best12. to date9 SAS

发布于 2020-04-15 10:31:10

Good afternoon

so I have BEST12.

enter image description here

I want to convert to date9.

so my code is

data step7_1;
set step7;
service_day2= input(put(datedate, z8.),yymmdd8.);
format service_day2 date9.;
run;

the error is

NOTE: Invalid argument to function INPUT at line 92 column 15.
NOTE: Mathematical operations could not be performed at the following places. The results of the
      operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      4 at 97:15

how can I fix this issue?

Thanks

Kazu

Questioner
supercool djkazu
Viewed
38
mjsqu 2020-02-04 05:22

A format is just a mechanism of displaying data, so there's no need to apply functions to 'convert' it, just apply a format using the format statement:

data step7_1;
    set step7;
    service_day2 = datedate;
    format service_day2 date9.;
run;

If you don't need a new variable, you can just use the format statement alone:

data step7_1;
    set step7;
    format datedate date9.;
run;

Or you can just alter the original dataset directly using PROC DATASETS:

proc datasets lib=work nolist;
  modify step7;
  format datedate date9.;
quit;

This has the advantage of not copying data, it will run more quickly and simply modifies the dataset metadata in place.