Never rely on a user to do things correctly. Perform the tests and checks in SAS, even if you have something in place in Excel to reduce the rate of incorrect or undesired data.
As an aside, there are also issues when importing from Excel because it does not have fixed character column lengths. SAS samples each sheet to guess the length and type of columns. If you use the same code to import from Excel on a regular basis, and you want to append the import to the previous imports, then you need to give some thought to the maximum column lengths over time.
An approach that I take is to import the data into a temporary sas table and then convert the data to a structure that you want.
I generally use a much more generic macro that converts all the columns to fit the template structure, but for the sake of simplicity, I have some (untested) code here.
I use a macro ut_varlist that I posted previously for which you can download the code, place it in an autocall macro library (or %include before you start
(Code for ut_varlist is in an attachment to https://communities.sas.com/t5/SAS-Programming/Macro-function-to-return-a-list-of-variables-in-a-tab...
Note that the code renames the column with the incorrect attributes, so that it does not clash with the column that you want to create. I am taking your word that the last_date column is blank and can there´fore by simply dropped. In my more generic macro (not here) I may have data that is imported as a text string but actually contains information that can be converted into a date.
/* set flag if last_date was imported as blank character */
%let date_is_char = %length(%ut_varlist(table=xlsx_temp_import, select=last_date, type=char) ne 0);
data final ;
set xlsx_temp_import
%if &date_is_char. = 1 %then %do;
/* rename the offending column */
(rename = (last_date=_last_date));
drop _last_date;
/* create the desired column */
format last_date date9.;
/* avoid warning */
call missing (last_date)
%end;
;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.