I'm new to SAS and Enterprise Guide and am having problems getting my head around some basic concepts. Please could someone explain the relationship between libraries, projects, libname and libref? I am following the SAS eLearning course but when I try to link a library with the datafiles stored on my machine I keep getting the message that the library doesn't exist, even though it's right there in the Server List.
Thanks in advance
I'm taking a college level SAS course atm. From what I have learnt, libref is a name in which you associate the physical location of a group of files to SAS.
The libname statement creates a library reference (libref) for a SAS program.
In general, the basic syntax of libname is:
libname libref 'path';
For example:
libname sales 'C:\salesdata\journal\june';
In other words, for SAS to be able to read and write data from a dataset, it must know the directory or folders that contains the particular dataset. SAS calls what we humans call directory or folders as "libraries". SAS also assigns nicknames (libref) to these libraries and use the libname statement to assign the nickname to a specific folder.
For example if you want to print an existing SAS dataset located inside the "june" folder, you can do this:
libname sales 'C:\salesdata\journal\june';
proc print data = sales.revenue;
run;
SAS will print the data portion of the "revenue" dataset that is located inside the "june" folder because we have assigned sales to that folder. Hope this helps.
Particularly if you're using SAS OnDemand for your training (as I assume you are), it's unlikely you will be able to directly assign a libname to your local datafiles. You'd have to provide more information as to the location/etc. of the datafiles you're trying to access to get a better answer, but in general, if you are running SAS on a server (Enterprise Guide is the GUI you're using to connect, SAS itself is the process that actually does the frequencies/etc. and is likely on a server somewhere, in the cloud or in your company's server farm).
The key concept is that a libname must be accessible on the machine running the SAS server instance. While it is possible you might have set up your network such that the server has mapped your local machine's hard disk to a drive, this is not the case in most instances. If you're on a network and you have access to a network drive that the SAS Server also has access to, you could share information that way; but if you are running SAS in the cloud (such as for training/educational purposes with SAS OnDemand), you probably cannot access any shared drives.
Chris Hemedinger (one of the SAS folk who used to work on EG) wrote a custom task, available at this link to help copy files from local desktop to remote server. This may not be helpful with SAS OnDemand, as I think those don't permit copying files up.
Related
I am trying to copy files from a folder on a SAS server to my local computer, I am trying to run the following codes connected to the server, and also disconnected from the server, but I am not getting positive results.
infile '/SASPrueba/Prueba_ALH/Libro1.xlsx';
file '/C:/Test/Libro1.xlsx';
input;
put _infile_;
run;
%sysExec move "\SASPrueba\Prueba_ALH\" "\C:\Test\";
I would appreciate if anyone knows how to perform this copying.
Most of the time, the SAS server cannot access your local machine's disks, unless you've set up a network share, which is not the case in most settings. You should instead use a network folder that both you and the SAS server can see, and place them there.
However, if you have access to Enterprise Guide, there is a task that lets you do this: the Copy Files task. It's built into SAS Enterprise Guide as of 7.13 (late 2017).
SAS Studio also has a similar option built in, "upload" and "download" in the Server Files and Folders tab.
You cannot execute either of these directly through SAS code, though - these are both point-and-click options.
If you really want to use SAS to do this rather than using an SFTP tool as per Tom's suggestion, you could try proc download:
rsubmit yourserver;
proc download
infile = '/SASPrueba/Prueba_ALH/Libro1.xlsx'
outfile = 'C:\Test\Libro1.xlsx'
binary
;
run;
endrsubmit;
rsubmit;
<Code>
endrsubmit;
This is useful if u are connected to the local server and you want to run a code on the remote. But how do I run a local script from the remote server? Is there something equivalent to localsubmit?
Additional Info:
I run most of my codes on the remote server because it is faster but I need to use the local SAS in two instances
There is one location with lots of space that I am unable to access through the remote server. I.e. it can be accessed as I:\folder1\folder2 but not as /folder1/folder2 (I tried finding a shortcut through filezilla but I guess the IT team has not created it)
Proc export with dbms = excel is only possible with a local server without which I cannot export multiple data in the same excel file (Which leads to a mess and would involve changing set processes/architecture that use dbms = excel)
You can only run code locally (on the machine on which EG installed) if you have a Base SAS licence. You will know this is the case if you open your SAS program (in EG), and check the values in the "Selected Server" dropdown. If you have a 'local' option you can run locally.
There is no concept of localsubmit. If you wanted to run code on your machine and trigger it from the server, your local machine would have to be configured as a SAS/Connect server and you would use rsubmit (with appropriate connection profile) from that server to your local machine. This would be a highly unusual scenario!
If I understand properly, at least for the second example there's a fairly common use case here.
What you'd do is to run the main program in rsubmit, and then in non-rsubmit block download the dataset created from the rsubmit block.
libname rwork slibref=work server=<yourserver>;
See this KB article for more information.
Then you could do it easily:
rsubmit server=myserver;
data class;
set sashelp.class;
run;
endrsubmit;
libref rwork slibref=work server=myserver;
data l_class;
set rwork.class;
run;
proc export data=l_class ...;
run;
Or even skip the l_class dataset and directly export from rwork.
For the first scenario, a large part depends on why you can't just not use rsubmit. Is the program located on the remote server, and you can't directly access it? You'd want to talk to IT I guess to find out how to directly access it.
I wonder if one of you can help me on how to upload all adventureworks database (every table) into SAS Studio?
I would like to work on adventureworks using sas base
All you need to do is create a libname reference to your database - I don't recommend creating SAS tables from the raw SQL Server data.
Example libref (using OLE DB):
libname &libref OLEDB
PROPERTIES=&sql_properties
DATASOURCE=&sql_dsn
PROVIDER=&sql_provider
SCHEMA=&sql_schema
authdomain="&sql_domain"
connection=shared;
You will need to set the relevant variables as per your environment.
It took a few years.. And the development of sasjs.. But finally, AdventureWorks for SAS is here!
Just run these two lines of code and the 5 AdventureWorks schemas will be created as different libraries under WORK:
filename mc url "https://raw.githubusercontent.com/sasjs/AdventureWorks/main/runme.sas";
%inc mc;
Just modify that file to make permanent libs / datasets. More info in the readme: https://github.com/sasjs/adventureworks
I've been searching for an answer on the Internet for the past few days and couldn't find any, so I'm posting the question here. Is there any way I can read SAS datasets that are stored in OneDrive without downloading or synchronizing it?
Is there any libname statement?
I don't use OneDrive, so I don't know how it works. But if you have a direct web-address like: onedrive.com/username/file.sas7bdat, then I know a code for importing Excel dataset. But I might work for SAS dataset too, at least you can try. The code is from the website.
FILENAME website url "http://www2.census.gov/acs2005/Tables_Profiles_Subject_Tables/010Nation/United%20States.xls" debug;
PROC IMPORT OUT= Readin DATAFILE= website
RUN;
You can not read a dataset without downloading it.
You need to map a local drive to your OneDrive account. There is a description of the process here. When this is done, you can apply a normal BASE engine libname statement to that drive.
%let user=scott;
%let password=tiger;
libname ora oracle user=&user password=&password;
options mprint mlogic symbolgen;
dm log 'clear';
in this way can we provide security to database?
so, i am trying to make security for my connection, if i clear my log that no one can see it.but once i close my sas section the library which i created will be vanished, so, can u please help me to create permanent library in order to make sure there is a connection with oracle after the section has closed.
You can add your libname statement to the autoexec.sas file. Here is how SAS looks for that file if you need to create one.
http://support.sas.com/kb/19/244.html
You can encode the password so you do not have to store it as plain text. Look at PROC PWENCODE -- http://support.sas.com/documentation/cdl/en/secref/66817/HTML/default/viewer.htm#n0dc6in0v7nfain1f2whl6f5x66p.htm
Another way to ensure security of your oracle credentials is to use dbprompt=yes in the LIBNAME statement. In this case you don't need to include your username and password into the statement - they will be prompted (in pop-up window) each time the library is being assigned. Which of course not so convenient, especially if you want this library to be assigned for every session. But security is worth of some sacrifices, I think...
It will work for SAS Base interface, but not for Enterprise Guide (when SAS-server is on the same local machine that EG itself, which is almost always the case): http://support.sas.com/kb/7/980.html
In this situation you can create user prompts using EG functionality (Prompt Manager). These prompts will assign your login and password entered into prompt window to macro variables, which you can then reference to in the LIBNAME statement.