All,
I am getting this below warning but all seems fine in the code.please advice me.
WARNING: Apparent symbolic reference FILENAME not resolved.
%macro test;
proc sql;
create table a(filename1 char(10));
insert into a values('test1.txt')
values('test2.txt')
values('test3.txt');
quit;
proc sql noprint;
select count(*)
into :fileCount
from a;
%put " file count is:%sysfunc(strip(&fileCount.))";
quit;
%do i=1 %to &fileCount.;
data _NULL_;
set a (firstobs=&i obs=&i); ;
call symput('filename',strip(filename1));
%put "&filename.";
run;
%end;
%mend test;
%test;
Thanks,
SS
data _NULL_;
set a (firstobs=&i obs=&i); ;
call symput('filename',strip(filename1));
%put "&filename.";
run;
The %put is resolved while the data step code is fetched for compiling, so this happens long before the data step actually runs. Move it after the RUN statement that ends the data step:
data _NULL_;
set a (firstobs=&i obs=&i); ;
call symput('filename',strip(filename1));
run;
%put "&filename.";
There is a timing issue when referencing macro variables in a data step. Basically they resolve in the compile phase prior to any data being read.
Your filename macro variable created this way will only have the value of the last value of filename1 any way.
If you want to create a bunch of macro variables from a data set you might consider
proc sql; create table a(filename1 char(10)); insert into a values('test1.txt') values('test2.txt') values('test3.txt'); quit; proc sql noprint; select filename1 into : file1- :file10 from a ; quit; %let filecount = &sqlobs; %put _user_;
As long as the number of the second :filexx is greater than or equal to the number of actual files in the data set it will only create one for each value. The automatic variable &sqlobs has the number of records returned from the last Proc SQL step, so saving it immediately after the Proc SQL step lets you have the iterator if needed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: