BookmarkSubscribeRSS Feed
Shmuel
Garnet | Level 18

It seems that not all cells of the column are defined as numeric.

Maybe in some rows the cells are defined as text.

In such case you need convert the text into numeric and make it as date format:

 

data want;

    set have(rename=(date=datex));

          if lengthn(datex) = 5 then date = input(datex,5.); 

          else date = input(datex, mmddyy10.);

         format date date9.;

run;

 

in case the dates in sas does not fit to the equivalent date of serial number of execl

you will need addapt it by a fix number of days.

SAS date count days since 01JAN1960 (serial number = 0);

while in excel 0 is: 00JAN1900

which means a difference of 21916 days.

Then change line to:

    if lengthn(datex) = 5 then date = input(datex,5.) - 21916 ; 

Okundaye1
Calcite | Level 5

It kind of worked, the years for the respective serial numbers came out as follows 

----> 2013 = 2073

----> 2015 = 2075 

----> 2016 = 2076

Shmuel
Garnet | Level 18
did you use:
if lengthn(datex) = 5 then date = input(datex,5.) - 21916 ;
ballardw
Super User

@Okundaye1 wrote:

Also why is SAS reading Date as a character variable ?


Because you have some of the data entered as text that Excel did not treat as a date when entered.

 

The solution I have had to this is generally: 1) make sure the column is formatted as a consistent date format in Excel. 2) Export the data to CSV 3) read with an appropriate INFORMAT. If the data is relatively clean then that Informat may be mmddyy10. or similar. Sometimes Anydtdte32.

And then 4) beat the data source about the head and shoulders with a wet noodle about poorly entered data. 😉

mkeintz
PROC Star

The internal SAS value for 1/1/1960 is 0.  The internal excel value for the same date is 21,916.

 

So after importing to SAS, you could

  1. Subtract 21916 from the improperly imported date values.
  2. Assign a SAS format to the variable.

This will work as long as you have no dates preceding Mar 1, 1900.  That's because visicalc mistakenly thought that 1900 was a leap year - an error preserved in its successor excel.

 

 

mk

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

@mkeintz wrote:

The internal SAS value for 1/1/1960 is 0.  The internal excel value for the same date is 21,916.

 

So after importing to SAS, you could

  1. Subtract 21916 from the improperly imported date values.
  2. Assign a SAS format to the variable.

This will work as long as you have no dates preceding Mar 1, 1900.  That's because visicalc mistakenly thought that 1900 was a leap year - an error preserved in its successor excel.

 

 

mk


AND Excel will accept 1/0/1900 as a valid "date" , enter 0 and format the cell as a date and see what you get.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 3595 views
  • 2 likes
  • 4 in conversation