BookmarkSubscribeRSS Feed
sathya66
Barite | Level 11

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

 

2 REPLIES 2
Kurt_Bremser
Super User
        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.";
ballardw
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 682 views
  • 0 likes
  • 3 in conversation