BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sreeni
Calcite | Level 5

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.



1 ACCEPTED SOLUTION

Accepted Solutions
Karthikeyan
Fluorite | Level 6

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

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

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.

Karthikeyan
Fluorite | Level 6

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

Sreeni
Calcite | Level 5

Tq very much Karthik .. Your suggestion worked out for me.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1263 views
  • 0 likes
  • 3 in conversation