%MACRO DOWNLOAD_BIB(DSN);
%chk_dir(dir=&path.\&DSN);
LIBNAME new "&path.\&DSN";
OPTIONS VALIDVARNAME=any;
signon Rsysv user="&_host_user" password="&_host_pass" noscript;
%SYSLPUT DSN=&DSN;
RSUBMIT;
OPTIONS VALIDVARNAME=any;
LIBNAME new "&DSN." DISP=SHR;
OPTIONS OBS=MAX;
PROC DOWNLOAD INLIB=new OUTLIB=new V6TRANSPORT;
RUN;
LIBNAME new CLEAR;
ENDRSUBMIT;
%MEND DOWNLOAD_BIB;
In this I am downloading SAS dataset from mainframe to windows
Macro variable path will have location where SAS dataset would be downloaded in windows
when I am ruuning the macro I am getting below error
ERROR: Cannot open data library new because it is uninitialized and user has has only read access.
can you help what is the error
First I would avoid calling the library reference new. That might cause problems. Second you have two initialisations of the library new, one with \&path.\&DSN, and one with just &DSN. Which one causes the issue. Posting the log really helps!!
Other than that, make sure you (i.e. the machine you work or or session) has access to the given areas.
And please avoid coding all in uppercase, no need to shout it at me.
what should I use in library reference other than new
error is coming after proc download step
You should put a descriptive bit of text which conforms to SAS naming conventions. In your code you create two lirary references called the same thing, and then copy from one to theo other. Which is going to cause errors:
LIBNAME new "&path.\&DSN";
LIBNAME new "&DSN." DISP=SHR;
PROC DOWNLOAD INLIB=new OUTLIB=new V6TRANSPORT;
^ Both in and out are the same libary!
RUN;
As an example correction:
%MACRO DOWNLOAD_BIB(DSN); %chk_dir(dir=&path.\&DSN); LIBNAME path_dsn "&path.\&DSN"; OPTIONS VALIDVARNAME=any; signon Rsysv user="&_host_user" password="&_host_pass" noscript; %SYSLPUT DSN=&DSN; RSUBMIT; OPTIONS VALIDVARNAME=any; LIBNAME dsn"&DSN." DISP=SHR; OPTIONS OBS=MAX; PROC DOWNLOAD INLIB=path_dsn OUTLIB=dsn V6TRANSPORT; RUN; LIBNAME new CLEAR; ENDRSUBMIT; %MEND DOWNLOAD_BIB;
You will see each library has a different reference.
I have changed the name of libraray reference now but still I am getting the error
Show your code, did you change both libnames to have different aliases like I showed? What errors or warnings? Do the libname paths exist, do you have rights to access them.
%MACRO DOWNLOAD_BIB(DSN); %chk_dir(dir=&path.\&DSN); LIBNAME outme "&path.\&DSN"; OPTIONS VALIDVARNAME=any; signon Rsysv user="&_host_user" password="&_host_pass" noscript; %SYSLPUT DSN=&DSN; RSUBMIT; OPTIONS VALIDVARNAME=any; LIBNAME getme "&DSN." DISP=SHR; OPTIONS OBS=MAX; PROC DOWNLOAD INLIB=getme OUTLIB=outme V6TRANSPORT; RUN; LIBNAME getme CLEAR; ENDRSUBMIT; %MEND DOWNLOAD_BIB; ERROR: Cannot open data library GETME because it is uninitialized and user has has only read access.
this is the code that i am running
And what does dsn resolve to?
LIBNAME getme "&DSN." DISP=SHR;
This DSN resolve to SAS dataset which resides in mainframe
for ex-SXXX.FGH.DFG.SAS
You have answered your own question then. Libname points to a path, not a dataset:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214133.htm
E.g.
%let path=c:/temp;
%MACRO DOWNLOAD_BIB(DSN); %chk_dir(dir=&path.\&DSN); LIBNAME outme "&path."; OPTIONS VALIDVARNAME=any; signon Rsysv user="&_host_user" password="&_host_pass" noscript; %SYSLPUT DSN=&DSN; RSUBMIT; OPTIONS VALIDVARNAME=any; LIBNAME getme "..." DISP=SHR; <-- Put the path to the server here ... OPTIONS OBS=MAX; PROC DOWNLOAD INLIB=getme OUTLIB=outme V6TRANSPORT; RUN; LIBNAME getme CLEAR; ENDRSUBMIT; %MEND DOWNLOAD_BIB;
From:
http://support.sas.com/documentation/cdl/en/connref/61908/HTML/default/viewer.htm#prcd.htm
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.