Hi there,
I am using SAS Studio. I am attempting to read a sas7bdat file into SAS Studio. I have tried the following:
LIBNAME x 'path to files on SAS Studio';
DATA dataset;
SET 'path to sas7bdat file in library';
RUN;
This says the file does not exist.
I have also tried:
DATA dataset;
SET library.filename;
RUN;
This says the file does not exist.
I have also tried this mapped to my computer folders, which does not work either.
So how many values did it find that contain non-ASCII characters?
What were some of the values?
Find the file in the Server Files and Folders window of SAS/Studio. Right click on it and get its properties. On of the properties will be its "path" (really its full name). That is the path would want to include in first data step.
To create a libref using the LIBNAME statement you just want the name of directory (what SAS/Studio likes to call a Folder) that file is in. So remove short name of the dataset file from the full name and use just directories name in the path in the LIBNAME statement. Then you can use the libref (the short (8 characters or less) nickname you used the LIBNAME statement to create) to refer to the dataset but just using its first name (without the .sas7bdat extension).
So if you have loaded a file onto the server where SAS is running and it full name is:
/home/gocojones/mydirectory/myfile.sas7bdat
Then you could use:
"/home/gocojones/mydirectory/myfile.sas7bdat"
or shorter just
"/home/gocojones/mydirectory/myfile"
to refer to it.
Or you could make a libref and then use a normal SAS two level name to refer to it. So if used this command
libname mydir "/home/gocojones/mydirectory";
to make a libref or MYDIR that points to the mydirectory "folder" then you could this name to refer to the dataset.
mydir.myfile
notice there are no quotes.
If you cannot find the file then you must first use the UPLOAD feature of SAS/Studio to copy the file to some place on the server where SAS is running.
If you find the file but any part of the short name of the file has uppercase letters then (unless your SAS server is running Windows) you will have to rename the file to replace the uppercase letters with lowercase letters. Unix is case sensitive and SAS is not, so it always looks for a file that is using lowercase letters only in the file.
Ahhhhhhhhhh okay the problem was that the file was in all caps I think! So I think I have the code right now:
The path to the file: /home/u59331558/LaF/STI/cohort1.sas7bdat
My code:
DATA DATASET1;
SET "/home/u59331558/LaF/STI/cohort1.sas7bdat";
RUN;
Now I am getting this message:
Have a look here https://communities.sas.com/t5/SAS-Viya/How-to-solve-this-ERROR-Some-character-data-was-lost-during/... on how to read and possibly convert the data.
Double-click on the SAS dataset (from Explorer tab) & see if it will open in the Table Viewer.
Hi Tom, I've done that but am getting this error:
Yes, the characters that were not identified are not really important to the research goal - how do I proceed past this?
I tried changing the default text encoding to windows-1252 as indicated in the link you provided and it still is showing the same error.
@gocojones wrote:
Hi Tom, I've done that but am getting this error:
ERROR: Some character data was lost during transcoding in the dataset GEISEL.COHORT1. Either the data contains characters that are not representable in the new encoding or truncation occurred during transcoding.any advice?
What encoding is your SAS session using? Check the system option ENCODING to see.
%put %sysfunc(getoption(encoding));
/* or */
proc options option=encoding;
run;
You will have most success using UTF-8 as the session encoding. The session encoding needs to be set when you start SAS. So for SAS/Studio sessions that means when you launch SAS/Studio. You might need to start with a different URL to get a "unicode" session that has encoding set to UTF-8. Or perhaps you can switch after you have started SAS studio
If you use ENCODING='ANY' dataset option then it should let you make a copy of the data.
You can then test for values that are not printable 7-bit ascii codes by doing something like:
data work.cohort1 ;
set geisel.cohort1 (encoding='any');
array _c _character_ ;
do over _c;
if verify(_c,collate(32,127)) then put _n_= _c= $hex. ;
end;
run;
And you should see in the SAS log the observation number (_n_) and the variable name followed by the HEX encoding of the value of the variable.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.