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

Hello guys,

 I need use a value of macro variable as a part of the filename path in file name statement for dynamic environment. But when I tried the below code macro variable 'src' not resolved so am not getting expected result.

Can any one help to overcome this??

data Temp1;
	set Temp;
	start_time1=datepart(start_time);
	call symput('Newdate',start_time1);
	call symput('src',ZP_FL_NM);
run;

%let filrf=myfile;

%let rc=%sysfunc(filename(filrf,
	"/D:/Folder/src"));

%let fid=%sysfunc(fopen(&filrf));
%let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
%let Fname=%sysfunc(finfo(&fid,Filename));
%let fidc=%sysfunc(fclose(&fid));
%put &Bytes &Fname;
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am guessing you need:

%let rc=%sysfunc(filename(filrf,
	"/D:/Folder/&src."));

Or something along those lines.  But why have the macro code using macro variables created from a datastep?  Just use the datastep to open the file and get number of bytes, i.e. all but about two lines are totally unecessary:
 

data temp;
fid=fopen(); bytes=finfo(fid,File Size (bytes)); Fname=finfo(fid,Filename); fidc=fclose(fid);
run;

And have a call symput if you need to at the end.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

You have created the macro variable &src, and then you never use this macro variable anywhere. Perhaps that is the problem?

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am guessing you need:

%let rc=%sysfunc(filename(filrf,
	"/D:/Folder/&src."));

Or something along those lines.  But why have the macro code using macro variables created from a datastep?  Just use the datastep to open the file and get number of bytes, i.e. all but about two lines are totally unecessary:
 

data temp;
fid=fopen(); bytes=finfo(fid,File Size (bytes)); Fname=finfo(fid,Filename); fidc=fclose(fid);
run;

And have a call symput if you need to at the end.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 5755 views
  • 0 likes
  • 3 in conversation