- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So how many values did it find that contain non-ASCII characters?
What were some of the values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Double-click on the SAS dataset (from Explorer tab) & see if it will open in the Table Viewer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Libname mydata "/home/u59331558/LaF/STI";
or
libname mydata "~/LaF/STI";
(~ will point to your user home directory).
Then you can refer to Libref (mydata) instead of the path:
DATA DATASET1;
SET mydata.cohort1;
RUN;
So the entire block of code would be:
/* this code will define a SAS libref to the folder /home/u59331558/LaF/STI */
libname mydata "~/LaF/STI";
/* this code will create a SAS dataset in the Work library, which is a copy of the cohort1 dataset */
DATA DATASET1;
SET mydata.cohort1;
RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Tom, I've done that but am getting this error:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
See https://blogs.sas.com/content/sgf/2018/06/22/a-transcoding-story-or-how-oliver-s-fusling-lost-his-la...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc contents data= GEISEL.COHORT1;
run;
It should tell you what encoding was used to create the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I tried
DATA DATASET1 ;
SET geisel.cohort1 (encoding=wlatin1);
RUN;
and got the same error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/movefile/n06qan4j3ffr6fn11bs4q11r8r56.htm