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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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