Where is the location of the SAS work folder? - sas

I want to attach a SAS dataset in my work folder to an email. But copying that directly from the "Explorer" pane in SAS 9.4 does not work. How do I get SAS to print the SAS work folder's actual location on disc?

Here are a couple ways to assign to macro variables.
proc options option=(work);
run;
%let workfolder=%sysfunc(pathname(WORK,L));
%put NOTE: &=workfolder;
%let %sysfunc(getoption(WORK,keyword));
%put NOTE: &=WORK;

The following prints the location of the work folder (usually multiple entries) from a SAS internal database.
proc sql;
select path from dictionary.libnames
where libname='WORK';
quit;
For my installation, this yields a location in C:\Users\USER_NAME\AppData\Local\Temp\SAS Temporary Files.

Related

ERROR: Physical file does not exist {on SAS studio (Academic ondemand-web based)}

I am combining two XPT files with following program code:
LIBNAME DM XPORT '/home/u62208181\DEMO.XPT';
LIBNAME QX XPORT '/home/u62208181\CDQ.XPT';
LIBNAME OUT '/home/u62208181';
DATA OUT.CDQ_DEMO;
MERGE DM.DEMO (KEEP=SEQN RIDAGEYR RIAGENDR)
QX.CDQ (IN=A);
BY SEQN;
IF A;
RUN;
Even though files are in folder- SAS show this error
Try converting the XPT to SAS data sets first.
Note that Unix is case sensitive, if you still get an error right click on the XPT file in the folder and copy the path from properties and paste that into your path.
LIBNAME DM XPORT '/home/u62208181/DEMO.XPT';
LIBNAME QX XPORT '/home/u62208181/CDQ.XPT';
LIBNAME OUT '/home/u62208181';
PROC COPY IN=DM OUT= OUT;
SELECT DEMO;
RUN;
PROC COPY IN=QX OUT=OUT;
SELECT CDQ;
RUN;
DATA OUT.CDQ_DEMO;
MERGE OUT.DEMO (KEEP=SEQN RIDAGEYR RIAGENDR)
OUT.CDQ (IN=A);
BY SEQN;
IF A;
RUN;
The \ character in Unix is used to "escape" the following character. So this path
/home/u62208181\DEMO.XPT
Is the same as
/home/u62208181DEMO.XPT
Which should not exist since only user directories should be in the /home folder and if it did exist you probably would not have access to it since it is not in your home directory.
Try using / instead.
/home/u62208181/DEMO.XPT
Note that the LIBNAME statements work because SAS does not know whether you are expecting to read from an existing file or create a new file. It is only when the code actually tries to read from the library that SAS warns you that the file does not yet exist.

List all Catalogs within a Library

As the title says: Is there a way to display all catalogs within a library like WORK using a PROC statement (or something similar)?
I tried PROC catalog and PROC datasets memtype=catalog but none of these seem to offer this option.
I am using SAS EG and indeed there is (at least in EG) a GUI way to list them via TOOLS -> Catalog and Formats Explorer and then one can browse through the libraries. However, I'd like to use a non-GUI approach and just couldn't find one so far.
You can use dictionary.catalogs, read more you can here. For example, to display catalogs from lib Work you can use this proc sql:
proc sql;
title 'Subset of the DICTIONARY.CATALOGS Table';
title2 'Rows with Library Name WORK';
select * from dictionary.catalogs
where libname ='WORK';
quit;
You can capture the ODS output portion of Proc CONTENTS that lists catalog members. The data= option will be {the libname}._ALL_
ods results off;
ods output contents.members=work.catalogs;
proc contents data=sashelp._all_ mt=catalog;
run;
quit;
ods results on;

list all SAS members in a ZOS libray from remote sas session

On our ZOS (mainframe) we have a library called
USER.PGM.WEEKLY
where several sas programs(members) are located
I am trying to retrieve a list of all the member from my PCSAS with following code
rsubmit;
proc source indd='C009BSA.BSA.BIBHLP.SAS' select *; print;run;
endrsubmit;
signoff;
But it errors out with
ERROR 22-322: Syntax error, expecting one of the following: ;, DIRDD, INDD, MAXIOERROR, NOALIAS,
NODATA, NOMEM, NOPRINT, NOSUMMARY, NOTSORTED, NULL, OUTBLK, OUTDD, PAGE, PRINT,
SEARCH.
ERROR 180-322: Statement is not valid or it is used out of proper order.
I have tried to google around to find the solution but haven't been able to sort it out.
How ever i am able to download one member at the time by running
filename inpds 'USER.PGM.WEEKLY' shr;
proc download infile =inpds(PPRINT_TO_PDF)
outfile='L:\Work\PPRINT_TO_PDF';
run;
Try something like this. You might need to use an actual physical file instead of using the TEMP filename engine on ZOS.
filename dirlist temp;
rsubmit;
filename dirlist temp;
proc source indd='C009BSA.BSA.BIBHLP.SAS' dirdd=dirlist; run;
proc download infile=dirlist outfile=dirlist; run;
endrsubmit;
https://v8doc.sas.com/sashtml/os390/z0217440.htm
If you just want to download all of the members of the PDS then PROC DOWNLOAD can do that for you without you needing to have the list of members.
filename outdir '/where/I/want/to/write/';
rsubmit;
filename indir 'C009BSA.BSA.BIBHLP.SAS';
proc download infile=indir(*) outfile=outdir; run;
endrsubmit;

Can I use wildcards in dataset names for PROC CONTENTS?

On the SAS server we have a library that contains thousands of datasets. I want to catalog the contents of a subset of these, all of which have names that begin with "prov". Can I use a wildcard to specify this?
I tried:
PROC CONTENTS DATA=library.prov*;
RUN;
But that just produces a log with this error message:
ERROR: File LIBRARY.PROV.DATA does not exist.
I also tried library.prov%, and that gave the same error.
There are over 100 datasets that start with "prov" so I really don't want to have to do them one at a time. Any ideas?
Depending on what information you want that the CONTENTS procedure produces you could just use the DICTIONARY metadata views.
proc sql ;
create table want as
select *
from dictionary.columns
where libname = 'LIBREF'
and memname like 'PROV%'
;
quit;
Use a WHERE data set option.
proc contents data=sashelp._all_ noprint out=class(where=(memname like 'CLASS%'));
run;
When you specify the keyword _ALL_ in the PROC CONTENTS statement, the step displays a list of all the SAS files that are in the specified SAS library.
Example :
PROC CONTENTS DATA=libref._ALL_ NODS;
RUN;
But to open only the datasets that begin with prov you can use the SQL and add CONTAINS to WHERE e.g:
proc sql ;
create table mytables as
select *
from dictionary.tables
where libname = 'WORK'
order by memname ;
quit ;
Now just run:
PROC CONTENTS DATA mytables;
RUN;
I may be using a different version of SAS check if you have the library SASHELP if so try this based on my note in your comment on the previous response you may see that this works out for you:
proc sql outobs=100;
create table see as
select distinct libname,memname,crdate,modate from sashelp.vtable
where libname='LIBRARY' and memname like 'PROV%'
order by memname;
quit;

How do I work with a SAS file that was created in a different format (Linux/Windows) if I don't have access to machine that created it?

I have numerous SAS datasets on my Windows 7 / SAS 9.4 machine:
data_19921.sas7bdat
data_19922.sas7bdat
data_19923.sas7bdat
....
data_200212.sas7bdat
etc. The format is data_YYYYM.sas7bdat or data_YYYYMM.sas7bdat (the latter for two digit months) and every dataset has identical variables and formatting. I'm trying to iterate over all of these files and append them into one big SAS dataset. The datasets were created on some Unix machine elsewhere in my company that I don't have access to. When I try to append the files:
%let root = C:\data;
libname in "&raw\in";
libname out "&raw\out";
/*****************************************************************************/
* initialize final data set but don't add any observations to it;
data out.alldata;
set in.data_19921;
stop;
run;
%macro append_files;
%do year=1992 %to 2002;
%do month=1 %to 12;
proc append data=out.alldata base=in.data_&year&month;
run;
%end;
%end;
%mend;
%append_files;
I get errors that say
File in.data_19921 cannot be updated because its encoding does not match the session encoding or the file is in a format native to another host, such as LINUX_32, INTEL_ABI
I don't have access to the Unix machine that created these datasets (or any Unix machine right now), so I don't think I can use proc cport and proc cimport.
How can I read/append these data sets on my Windows machine?
You can use the colon operator or dash to shortcut your process:
data out.alldata;
set in.data_:;
run;
OR
data out.alldata;
set in.data19921-in.data200212;
run;
If you have variables that are different lengths you may get truncation. SAS will warn you though:
WARNING: Multiple lengths were specified for the variable name by input data set(s). This may
cause truncation of data.
One way to avoid it is to create a false table first, using the original table. The following SQL code will generate the CREATE Table statements and you can modify the lengths manually as needed.
proc sql;
describe table in.data19921;
quit;
*run create table statement here with modified lengths;
data out.alldata;
set fake_data (obs=0)
in.data19921-in.data200212;
run;