BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
gocojones
Calcite | Level 5

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So how many values did it find that contain non-ASCII characters?

What were some of the values?

View solution in original post

17 REPLIES 17
Tom
Super User Tom
Super User

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.

 

gocojones
Calcite | Level 5

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:

 

NOTE: Data file WC000001.COHORT1.DATA is in a format that is native to another host, or the file encoding does not match the session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce performance. 72 RUN;
 
ERROR: Some character data was lost during transcoding in the dataset WC000001.COHORT1. Either the data contains characters that are not representable in the new encoding or truncation occurred during transcoding.
 
NOTE: The DATA step has been abnormally terminated.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 270 observations read from the data set /home/u59331558/LaF/STI/cohort1.sas7bdat.
 
WARNING: The data set WORK.DATASET1 may be incomplete. When this step was stopped there were 270 observations and 2220 variables.
 
 
 
I know that I should have 612 observations and 2220 variables - so at least that part is right.
 
 
tom_grant
SAS Super FREQ

Double-click on the SAS dataset (from Explorer tab) & see if it will open in the Table Viewer.

tom_grant
SAS Super FREQ
Best practice is to assign a Libref to the folder that contains your SAS data. In your case:
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;
gocojones
Calcite | Level 5

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?
tom_grant
SAS Super FREQ
I would try opening the new dataset with the table viewer (double-click new SAS dataset COHORT1 in the GEISEL library. You may find that these characters that were not identified are not really important to the research goal (like foreign names).
See https://blogs.sas.com/content/sgf/2018/06/22/a-transcoding-story-or-how-oliver-s-fusling-lost-his-la...
gocojones
Calcite | Level 5

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. 

Tom
Super User Tom
Super User

@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

Tom_0-1691608388245.png

 

gocojones
Calcite | Level 5
It was originally UTF-8, but I tried windows-1252 and a couple of others as well.
tom_grant
SAS Super FREQ
Try running proc contents on the original file:
proc contents data= GEISEL.COHORT1;
run;
It should tell you what encoding was used to create the file.
gocojones
Calcite | Level 5
wlatin1 was used for the original file. I do not see an option to change encoding to wlatin1 unfortunately.

I tried
DATA DATASET1 ;
SET geisel.cohort1 (encoding=wlatin1);
RUN;

and got the same error.
Tom
Super User Tom
Super User

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 17 replies
  • 7670 views
  • 0 likes
  • 5 in conversation