BookmarkSubscribeRSS Feed
SASHunter
Obsidian | Level 7
Hi,

I am trying to write code to create a SAS dataset from an Excel file. There are no variable Names in the Excel file. I want to be able to read in the Excel file and create the SAS file and have the system create Variable names, not use the first observation as the variable name.

This is my code:

libname excel "H:\Testing\testfile.xls";
libname temp "c:\Temp";

data temp.new_sas_file;
set excel."Sheet1$"N;
run;

proc print;
title1 "Test file";
run;
libname excel clear;

It creates fine, but the first observation is used as the variable names.
Also, can you tell me what the 'N' stands for in the set statement? I thought maybe it meant NO for get names.

I created it fine using the PROC IMPORT, but wanted another way.

Can someone tell me what I am doing wrong.

Thanks, Nancy
3 REPLIES 3
SASKiwi
PROC Star
I suggest you check in SAS help for the options associated with using LIBNAME for reading Excel spreadsheets. The documentation states that if you specify HEADER = NO then SAS will generate column names F1, F2 etc. instead of using the first row.
SASHunter
Obsidian | Level 7
Thanks,

I looked up the HEADER=NO and read a SAS paper called "How to Excel with SAS".

This gave me the information on using the LIBNAME statement and Header=no. That worked great.

Still I have this question; is there a way when you have Excel open that you can use the SAS Addin tab (or SAS Solutions tab) and navigate to the file you have in excel and create a SAS dataset from it? My SAS Solutions tab only has the 'Log On' control enabled, but when I click it - it says "A problem has been encountered reading the .ini file".


Thanks so much,

Nancy

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 5505 views
  • 0 likes
  • 3 in conversation