BookmarkSubscribeRSS Feed
_Hopper
Obsidian | Level 7

How can I force proc import to create all character variables in the output dataset from the Excel workbook?

I can also get a csv version if that makes it easier.

 

The spreadsheet I'm working with has several hundred columns and most have numeric values, but in some, dashes exist. 

2 REPLIES 2
Reeza
Super User

CSV would probably make it easier. Is the - the value for missing that is being interpreted as a character for your numeric variables. 

Tom
Super User Tom
Super User

If you are importing an EXCEL file and the header row has NAMES then it usually works to use GETNAMES=NO so that it treats the first observation as data.  

proc import file=xlsx dbms=xlsx out=want replace;
  getnames=no;
run;

You can then use the first observation to generate code to rename the variables if you want and at the same time delete that observation.

proc transpose data=want(obs=1) out=names ;
  var _all_;
run;
proc sql noprint;
  select catx('=',_name_,nliteral(col1)) into :renames separated by ' '
  from names;
quit;

data want;
  set want(firstobs=2);
  rename &renames;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 251 views
  • 5 likes
  • 3 in conversation