Help using Base SAS procedures

PROC IMPORT wrong data type

Reply
New Contributor
Posts: 2

PROC IMPORT wrong data type

Hi, could anyone provide me with understanding of the following:

Situation: I am importing with PROC IMPORT experimental response data stored in five Excel sheets (response data for five different coating types). In each sheet, the response column has 300 obs, all numeric values except for a (very) few missing values denoted in the sheet by a dot (.). Only two of the five sheets have missing responses.

Problem: For the two sheets that contain missing values, SAS imports the response column as character datatype.

I understand that the datatype for the column is determined based on the first 8 rows. The missing values are way below these first rows, so 100% sure SAS should import this column as numeric datatype. Why doesn't it?! How to remedy?!

FYI:

%MACRO makeds;

%do i=1 %to 5;

filename ref '...&i..xls';

PROC IMPORT out=work.intermediate datafile=ref dbms=xls replace;

sheet="Sheet1";

RUN;

DATA mylib.coating&i;

     set work.intermediate;  --> intermediate dataset has character column when sheet contains some missing values (.), why??

     coating=&i;

RUN;

%end;

%MEND makeds;

Many thanks for your insights!

PROC Star
Posts: 7,357

PROC IMPORT wrong data type

use the guessingrows option

New Contributor
Posts: 2

Re: PROC IMPORT wrong data type

Ok, I did, now all five sheets are imported with response column as character datatype...even worse Smiley Happy

Also it says guessingrows is invalid option. XLS are not delimited files, while guessingrows option is restricted to delimited files.

Super User
Posts: 10,476

Re: PROC IMPORT wrong data type

I believe the behavior you are seeing is because of the EXCEL data engine not SAS.

I know of two work arounds 1) don't let the Excel sheet get populated with the (.)

2)save each sheet as CSV and then the problem either goes away or the guessingrows will work.

PROC Star
Posts: 7,357

Re: PROC IMPORT wrong data type

Depending upon how old a version of excel you are using, there is another option:

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1007A&L=sas-l&P=R3424&D=1&H=0&O=D&T=1&m=315710

It was for the older excel versions and I haven't seen an update for 2007+ if you happen to be using a newer version.

Super User
Posts: 9,671

Re: PROC IMPORT wrong data type

Did you try to use option

mixed=yes

This will produce character variable if your column is mixed with number and non-number.

Ksharp

Ask a Question
Discussion stats
  • 5 replies
  • 1560 views
  • 1 like
  • 4 in conversation