DM command to open last dataset in rwork library - sas

dm "vt &syslast";
The above command opens the last created dataset in work library.
How do I make it work for RWORK library?

dm "vt &syslast." will open the most recently created table, regardless of what location it is stored in. So if the most recently created table is in RWORK, that should not be a problem.
What might be a problem is the definition of &syslast, however. If you are doing something like:
rsubmit;
data class;
set sashelp.class;
run;
endrsubmit;
dm "vt &syslast.";
That won't work - &syslast is defined on the remote computer, not on your local computer. You either need to use %sysrput to put the macro variable onto your local machine, or know the name of the dataset you want to open.
rsubmit;
data class;
set sashelp.class;
run;
%sysrput rdata=&syslast;
endrsubmit;
dm "vt &rdata";
Or something along those lines. I think you'd probably have to translate the libname - &rdata would contain WORK.CLASS here, and you'd have to add an R - but it might be as simple as:
dm "vt R&rdata";
since you just want to prepend an R.
You could also directly specify the table, dm "vt rwork.tablename", and open any arbitrary table.
DM commands only work in SAS Display Manager environment (often called "Base SAS") and will not work in Enterprise Guide or SAS Studio. Both EG and Studio automatically open tables created during the current submission, by default, though the option to do so can be turned off.

Related

Read a sas7bdat file in SAS Studio

I've scoured the internet but cannot seem to figure this out. My question is, if I have a sas7bdat file, how can I read a sas7bdat file in SAS studio so that I can work with it.
I've tried:
libname test 'C:\Users\name\Downloads\test.sas7bdat';
which gives me the error that library test does not exist and if I try the following, I know that I need an INPUT which I don't know of unless I can see into the file.
DATA test;
INFILE 'C:\Users\lees162\Downloads\test.sas7bdat';
RUN;
Is there something I'm missing?
Libref's that you create via the LIBNAME statement point to directories, not individual files.
libname test 'C:\Users\name\Downloads\';
INFILE is for reading raw data files. To reference an existing SAS dataset you use a SET statement (or MERGE,MODIFY,UPDATE statement).
set test.test ;
Note that you can skip defining a libref and just use the quoted physical name in the SET statement.
DATA test;
set 'C:\Users\lees162\Downloads\test.sas7bdat';
RUN;
Of course to use C:\ in the paths this is assuming that you are using SAS/Studio to point to full SAS running on your PC. If you are using SAS University Edition then it is running in a virtual machine and you will need to put the SAS dataset into a folder that is mapped to the virtual machine and then reference it in the SAS code with the name that the virtual machine uses for the directory.
So something like:
DATA test;
set '/folders/myfolders/test.sas7bdat';
RUN;
Libname is just pointing the location and once you have done that you can use that libname followed period and dataset in your set statement
libname test "C:\Users\name\Downloads";
DATA test;
set test.asl;
RUN;
One possible reason could be that you are using the SAS University edition (It doesn't support variable library address).
From one of the SAS community Q/A:
"When you are using the SAS University Edition, any libraries that you create must be assigned to a shared folder. You access your shared folder with this pathname: /folders/myfolders/. Always use '/' in the directory path, even in Windows operating environments"
After setting the directory address, proceed as instructed by Tom above in one of the answers.
Suppose you have the sas dataset at location. C:\Users\name\Downloads\test.sas7bdat
libname download 'C:\Users\name\Downloads';
proc sql;
select * from downloads.test;
run;
you can read your dataset like a table using the proc sql, in case you want to query the dataset, but if you want to modify the existing dataset then you can use the data setp as mentioned by #krian.

Export .sas7bdat from SAS Studio to local machine

I am using SAS Studio(completely browser based). I need to export a dataset to my local machine in the .sas7bdat file format. I think it should be something like PROC EXPORT data = sqrtReg2 outfile = "C:\Documents\SAS\Target_Wins.sas7bdat";. But that returns the error ERROR: Unable to determine datasource type. Please use the DBMS= option.. But the DBMS option only allows for CSV, tab and DLM. How do I export this data set to my local machine in the .sas7bdat file format?
With the SAS University Edition you can setup shared folders in the virtual machine where SAS runs that are mapped to actual folders on your real machine.
For example you might have mapped C:\Documents\SAS\ to /folders/myfolders. You cannot write to other locations on your real machine that are not mapped so that the virtual machine can see them. Check the documentation for exact details of getting the folders mapped.
The normal way to have SAS place a dataset then is to create a libref that points to the folder and then use a two level name when referencing the data set. You could create a libref named OUT for example:
libname out '/folders/myfolders/';
data out.target_wins;
set sqrtReg2;
run;
But you can also just refer to the file directly without first creating a libref.
data '/folders/myfolders/target_wins';
set sqrtReg2;
run;
Note that since SAS is actually running in Unix you cannot use CamelCaseFileNames for your SAS datasets. The files will always be in all lowercase letters.
None of the answers worked for me. Maybe because after April 2021, they have made changes to the platform(University). So, after a lot a time searching, I found what I needed.
You can easily export the sas dataset to csv, xslx, by just right clicking on the dataset and selecting export as csv, xlsx, etc.
For exporting to sas7bdat file, do:
Create your dataset, I am creating from csv, so create a program1(.sas) to first convert csv to sas dataset.
proc import file="/home/u123/mydata.csv"
out=work.mydata
dbms=csv
replace;
run;
This will create your sas dataset.
IMP Go to "Libraries" at the right bottom, and hit "My Libraries" -> New Library -> Name it(eg - test), give path(eg - /home/u123/sasuser.v94)
Check library creation, and HIT "Refresh Library Session" on right pane, don't refresh the page.
Now create a separate program2(.sas), to export the dataset to .sas7dbat file.
PROC COPY IN=WORK OUT=test;
SELECT mydata;
run;
quit
This will create a .sas7bdat file in your directory, with same name as your dataset.
These exact steps worked out for me.
It won't work for 2 reasons.
You can't export a SAS dataset to a SAS dataset (.sas7bdat) - Proc Export will export to excel, csv, etc but not to a .sas7bdat.
you're running SAS Studio from within a Virtual Machine that uses Linux as OS so path to create an external file is incorrect. You haven't hit this error but you will once you use the right filetype.
When you installed SAS Studio you should have created a shared folder. This folder is accessed from within SAS Studio as /folders/myfolders/filename.
So your code should looks like this:
PROC EXPORT data = sqrtReg2
outfile = "/folders/myfolders/Target_Wins.csv";
run;
From Windows the path to this shared folder will depend upon where you installed your VM.
Option 2
If what you need is the dataset then try the following code:
libname out "/folders/myfolders/";
proc copy in=work out=out;
select sqrtReg2 ;
run;
Again, table will be in your shared folder which is accesible from Windows.
I used just like option 2 in the above answer. I need to export my polygon data from SAS Studio in my virtual machine so that i can import it to my Visual Analytics. and it worked just fine.
libname out "/folders/myfolders/";
proc copy in=work out=out;
select my_map;
run;

How to find SAS version from SAS Enterprise Guide?

In my previous work place where I had access to base SAS (running SAS interactively on the server directly), I could find out the current SAS version easily (from the SAS log) by issuing the code proc setinit; run;
In my new work place there is no base SAS - only Enterprise Guide. I try running the same code but the SAS version does not appear in the SAS log.
I would like to easily find out the SAS version running on the server from Enterprise Guide. Is this possible or not? If so, how?
The values you're looking for are stored in automatic macro variables in your system. The code below retrieves the macro variables and prints them to the log for your information.
%put ** my information;
%put short version: &sysver;
%put version: &sysvlong4;
%put site #: &syssite;
%put cpu: &sysscp &sysscpl;
EDIT: Update answer
You can use PROC PRODUCT_STATUS which is great, since it will print the relevant information to the log.
proc product_status;run;
There are some other options available rather than using the global macro variables (&sysver and &sysvlong4), if you prefer point-click options.
First, under Help -> About SAS Enterprise Guide, if you select 'Configuration Details' you can see your SAS system version.
Second, if you select the server in the Servers tree (in the window on the bottom left), and right click->Properties, you will see the SAS version/etc. information.
Third, if you continue in that and select "View Initialization Log", it will show you the initialization log (the bit SAS shows when you start a session in the log). This includes the version number and some other useful information.
Just run the following code and all available information will be printed automatically.
proc setinit;
run;
You can also use
%put _all_;
that will display all macro variables available in your session.
proc setinit;
run;
You can run this set of code and check the results. It will tell you the version you are using.
%put &_clientversion; gives you version.
proc setinit;
run;
Or under the help tab in the top left of the enterprise guide.

where data get stored in sas by using stored process. using local server(work space) option

I am using stored process for running bunch of queries and in that i am creating tables.Code runs perfectly but where the table getting stored,i am not getting it?Since in log it shows no errors. Similarly i used proc univariate, result's are displaying but where that result getting stored?I am using using local work space library to store.
As you said, your results are stored in work library. If you want to know where it is, you can see the path by running this code:
%put %sysfunc(getoption(work));
Keep in mind that work library reference is temporary and only relevant to your current session. Also, all datasets are temporary and they get wiped at the end of your SAS session.
For proc univariate, you have to specify OUT= option and point where you want your summary statistics to be saved. If the report that you are after, use ODS destinations to save it to a permanent location.
Regards,
Vasilij
To find the path being used by a libname (in this case the work libname), use this code:
%put %sysfunc(pathname(work));
For any output, it depends on your system setup, how SAS is started, etc... Your output does not necessarily go to the same folder as your work libname uses.
I would use this code in windows:
filename x pipe 'echo %cd%'; * WINDOWS COMMAND TO RETURN CURRENT WORKING DIRECTORY;
data _null_;
infile x;
input;
put _infile_;
run;
In *nix, change the filename statement to:
filename x pipe 'pwd'; * UNIX/LINUX COMMAND TO RETURN CURRENT WORKING DIRECTORY;
Or, as Vasilij suggested, use the OUT= option of the ODS statement.

Bulkload w/Proc Append

Relatively new to SAS and looking to bulkload data - pipe delimited .dlm - into a MySQL database. I've got the basics nailed down, I believe anyway, but I'm stumped on how to tell SAS the beginning and endings of a data row. Current syntax...
proc append base=abc.metrics (bulkload=yes
bl_delimter='|'
bl_options='errors=0'
bl_delete_datafile=no)
data=abc_metrics_&jid;
run;
Any thoughts, guidance, and comments would be appreciated.
I don't think you can directly do this for MySQL:
http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#a002938849.htm
http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#a001752476.htm
However, you can write out the file yourself. Change sashelp.class to your dataset, file "\server\yourfile.dlm", and if you need | after the last record prior to ~, remove that +(-1).
data _null_;
set sashelp.class;
file "c:\temp\test.dat" dlm='|' lrecl=32767;
put "!" #;
put name $ age height weight #;
put +(-1) "~";
run;
Then you can call MYSQL's bulk loading facility (whatever that is) as you normally would; you may be able to use a passthrough connection, ie,
proc sql;
connect to odbc (connection-information);
execute ("load file.dlm into table") by odbc;
quit;
(obviously bad sql syntax there, but that's the concept - anything in that " " is executed directly on the MySQL box as MySQL code as if you were in the DB's interface directly).
Or, if MySQL has something like Oracle's SQL*Loader, you can call that from the command line assuming you have access to it, using the 'x' command.
As far as I know, you cannot directly "bulk load" from SAS to MySQL, See this note in the SAS Access manual.
So, your best bet is to create a delimited text file (perhaps with PROC EXPORT) and use a mysql utility. Here is a previous SO question with various solutions, particularly the one about the load data local infile command.