Dear SAS community,
I have the following asignment:
In this practice, you will create a table that contains a copy of the data that from an Excel workbook. The Excel workbook contains a single worksheet.
Open p102p01.sas from the practices folder. Complete the PROC IMPORT step to read eu_sport_trade.xlsx. Be sure the replace FILEPATH with the path to your EPG1V2 > data folder.
Create a SAS table named eu_sport_trade and replace the table if it exists.
Modify the PROC CONTENTS code to display the descriptor portion of the eu_sport_trade table.
Submit the program, and then view the output data and the results.
=========
my code was set up as follows and got errors:
LOG:
Thank you for your time for comment.
Look very carefully at the PATTERN of the two path names you used:
"/home/u63717210/EPG1V2/practices" "pps/p102p01.sas/eu_sport_trade.xlsx"
What differences do you see:
The first one starts with /, the root node of the Unix file system, and the second one does not.
That means that the operating system will treat the first one as an ABSOLUTE (or complete) path and the second one as a RELATIVE path. When you use a RELATIVE pathname the operating system starts at the current working directory and begins evaluating the path. So what file it is looking for depends on the setting of the current working directory.
Thank you so much for your comment.
I regret not to ask directly.
My code was initially as like this:
proc import Datafile= " /home/u63717210/EPG1V2/practices/p102p01.sas/eu_sport_trade.xlsx"
Here error happened because "practices" is over 8 characters. In this situation, how I can circumvent the 9 characters of practice to avoid errors?
Thank you again for your generous comment.
The code you shared does not (and should not) get any errors about something being longer than 8 characters.
Instead it shows that the file you tried to IMPORT from does not exist because you told SAS to look for it in the wrong place.
ERROR: Physical file does not exist, /pbr/biconfig/940/Lev1/SASApp/pps/p102p01.sas/eu_sport_trade.
Perhaps you tried to make a LIBREF using a name that was longer than 8 characters? The libref you use in a LIBNAME statement has to be a valid SAS name between one an eight characters. Its value does not have to match the name of the directory that it points to. So if you want to make a libref pointing to that practices folder you could call it PRACTICE or FRED or SAM or any other valid SAS name (that is not already being used from some other libref.
libname fred "/home/u63717210/EPG1V2/practices/";
proc import out=fred.myds ...
Thank you for the comment.
The code changed to the following:
libname pract xlsx "/home/u63717210/EPG1V2/practices/p102p01.sas/eu_sport_trade.xlsx";
proc import Datafile=pract
dbms=xlsx
out=eu_sport_trade replace;
run;
proc contents data=eu_sport_trade;
run;
Log:
PROC IMPORT reads from files, not from libraries. If you don't want to include the actual filename in the PROC IMPORT code then use a FILENAME statement to create a FILEREF.
filename pract "/home/u63717210/EPG1V2/practices/p102p01.sas/eu_sport_trade.xlsx";
proc import
datafile=pract
dbms=xlsx
out=eu_sport_trade replace
;
run;
proc contents data=eu_sport_trade;
run;
If you want to have SAS make the workbook look like a library by using a LIBNAME statement with the XLSX engine then there is no need to use PROC IMPORT. Instead if you know the name of the worksheet then you can just reference it directly. So if the sheet is named eu_sport_trade then just use that with the LIBREF that you created to reference the data.
libname pract xlsx "/home/u63717210/EPG1V2/practices/p102p01.sas/eu_sport_trade.xlsx";
proc contents data=pract.eu_sport_trade;
run;
If you don't know what the sheets are named then you might try just copying all of the sheets into datasets in the WORK library.
libname pract xlsx "/home/u63717210/EPG1V2/practices/p102p01.sas/eu_sport_trade.xlsx";
proc copy inlib=pract outlib=work;
run;
After you see the names in the SAS log you will know what dataset name to use in your PROC CONTENTS code.
One caution with using Excel files as libraries to read data into SAS: They must be clean.
That means column headings only one cell starting on the first row, all the data in a column the same, i.e. numeric with the same type (all dates, all currency, all simple numbers, no mixing) or character. If the Excel is actually more of a report appearance then likely the library approach will lead to much frustration.
If the Excel has two or more column headings then the column will likely be treated as character. If there are one or more blank cells above the headings you will likely again have the column treated a character (and possibly records with missing values).
At one point in my working career I would say that nearly 20 percent of my work time was cleaning up Excel "data" that the creators could not, or would not, keep consistent in any structure. When the Excel library was introduced in SAS I had one project that it seemed a reasonable solution to the read the frequent files provided. Lasted 3 weeks before the first file change.
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.