Hi,
I need to access a mainframe dataset (SAS file) from SAS Program.
I cannot pass the Dataset name from JCL as the file name is not fixed.
Eg ... File Name is : HLQ.SLQ.TLQ.A&YYMMDD.
In SAS program I can derive YYMMDD and can be able to make up the File name.
I need assistance for how to refer the file name and access it from SAS program.
I am trying the following :
Getting current date as : 20150407 in SAS program.
%LET FNAME = HLQ.SLQ.TLQ.A&YYMMDD;
%PUT &FNAME;
FILENAME INFIL "&FNAME"
DISP=SHR;
DATA WANT;
SET INFIL;
RUN;
The above is giving error. File name is resolving properly (HLQ.SLQ.TLQ.A150704) but its giving me error stating Error in the FILENAME statement.
File WORK.INFIL.DATA does not exist.
Can some one please assist how to access the Dataset (File) from SAS Program.
Where as If I pass the the dataset name as HLQ.SLQ.TLQ.A150704 from JCL then its working fine (just putting the DD Name mentioned in JCL at SET is working fine).
Regards,
Sree.
If you need to refer a permanent dataset created sometime back , you should use the libname statement to point the the dataset librarary and then you can access the dataset by two level name.
Eg:
If my dataset library is "BAS0000.XXX.YY.DATA" and the Dataset name is HAVE.
libname Mydata 'BAS0000.XXX.YY.DATA';
Data
WANT
;
Set
Mydata.HAVE
;
Run;
If you want to refer a Dataset created in the same SAS session but you have to derive the Dataset name dynamically , you can do something like
DATA
WANT
;
SET
HLQ.SLQ.TLQ.A&YYMMDD
;
RUN;
FILENAME should be used only when we had to access the OS files like reading or writing to a file.
Thanks
Karthik
If it is working fine referencing the DDNAME on the SET statement why are you trying to allocate it a second time in SAS? In any case to allocate a SAS data library in SAS you need a LIBNAME statement not a FILENAME statement.
If you need to refer a permanent dataset created sometime back , you should use the libname statement to point the the dataset librarary and then you can access the dataset by two level name.
Eg:
If my dataset library is "BAS0000.XXX.YY.DATA" and the Dataset name is HAVE.
libname Mydata 'BAS0000.XXX.YY.DATA';
Data
WANT
;
Set
Mydata.HAVE
;
Run;
If you want to refer a Dataset created in the same SAS session but you have to derive the Dataset name dynamically , you can do something like
DATA
WANT
;
SET
HLQ.SLQ.TLQ.A&YYMMDD
;
RUN;
FILENAME should be used only when we had to access the OS files like reading or writing to a file.
Thanks
Karthik
Tq very much Karthik .. Your suggestion worked out for me.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.