BookmarkSubscribeRSS Feed
xiangpang
Quartz | Level 8

I have some following SAS code in macro:

 

 

It produces the correct output but with log warnings:

 

WARNING: Apparent symbolic reference name not resolved.

 

I searched

%macro page (filein=, ls=, numofpages=); 

data _null_;
   infile "&filein." length = vlg ;
   input @1 line $varying&ls.. vlg;
   if _n_=1 and line="" then delete;
   if _n_=1 then call symput("name",line); run;

data odsprn_;
   retain num 1 pageno 0 lineno 0;
   length line $&ls..;
   infile "&filein." length=vlg end=fin;
   n=_n_;
   numpages=&numofpages.*1;
   input @1 line $varying&ls.. vlg;

   if upcase(substr(line,1,length(line))) = upcase(substr("&name.", 1)) then put _page_;
.
.
.

run;
%mend;

%page (filein=try, ls=15, numofpages=100); 

the forum and found it could be because 'name' is not assigned as a macro variable.

 

I tried to add %global name; but still have the warning. 

 

Could anyone help me to figure out how to remove the warning ?

9 REPLIES 9
Reeza
Super User

In this condition you delete the record and may not have a macro variable. How do you want to handle that situation?

 

if _n_=1 and line="" then delete;

 


@xiangpang wrote:

I have some following SAS code in macro:

 

 

It produces the correct output but with log warnings:

 

WARNING: Apparent symbolic reference name not resolved.

 

I searched

%macro page (filein=, ls=, numofpages=); 

data _null_;
   infile "&filein." length = vlg ;
   input @1 line $varying&ls.. vlg;
   if _n_=1 and line="" then delete;
   if _n_=1 then call symput("name",line); run;

data odsprn_;
   retain num 1 pageno 0 lineno 0;
   length line $&ls..;
   infile "&filein." length=vlg end=fin;
   n=_n_;
   numpages=&numofpages.*1;
   input @1 line $varying&ls.. vlg;

   if upcase(substr(line,1,length(line))) = upcase(substr("&name.", 1)) then put _page_;
.
.
.

run;
%mend;

%page (filein=try, ls=15, numofpages=100); 

the forum and found it could be because 'name' is not assigned as a macro variable.

 

I tried to add %global name; but still have the warning. 

 

Could anyone help me to figure out how to remove the warning ?



 

xiangpang
Quartz | Level 8

I am really surprised you find the issue. 

the original code does not have 'if _n_=1 and line="" then delete;'. the problem is without this line of code, the first page of output is blank, while the output figure is in next page. 

so I add ' if _n_=1 and line="" then delete;' making the output right. but got this warning.  

 

Do you have other way?

 

Thanks

Reeza
Super User

@xiangpang wrote:

I am really surprised you find the issue. 

the original code does not have 'if _n_=1 and line="" then delete;'. the problem is without this line of code, the first page of output is blank, while the output figure is in next page. 

so I add ' if _n_=1 and line="" then delete;' making the output right. but got this warning.  

 

Do you have other way?

 

Thanks


It depends, at this point it depends on what's in the input file and what you're trying to account for there, which I do not know. 

What happens if that file doesn't have the value you need though? You're not accounting for that case. 

 

The output page issue be coincidental or indicative of a different issue in your process. 

xiangpang
Quartz | Level 8

input file has a figure with a name. I think the original code logic is when first line is not blank then name following the figure will be inserted. 

Reeza
Super User

We cannot see any of that and still doesn't really relate to the output code as that's input. 

 

EDIT: the problem is in your code, which you're not showing. You don't have to show the actual data, in fact it's preferable to simplify it and use example data and links to illustrate the problem. If you can't illustrate it with sample data then you usually know it has something to do with your system/data. 

 


@xiangpang wrote:

input file has a figure with a name. I think the original code logic is when first line is not blank then name following the figure will be inserted. 


 

Patrick
Opal | Level 21

Using your code to derive the logic it appears you only need to read the very occurrence where line is not missing to populate macro variable &name. If that's true then code as below should do.

%let name=;
data _null_;
  infile "&filein." length = vlg;
  input @1 line $varying&ls.. vlg;
  if not missing(line) then
    do;
      call symput("name",line);
      stop;
    end;
run;
xiangpang
Quartz | Level 8

Thanks for your reply. I just tried your code. It has no warning message but still the first page is blank, same as original code without 'if _n_=1 and line="" then delete;'.

 

could you make the first line is not blank when _n_=1 , while  populate macro variable &name?

Reeza
Super User
I think that's a separate issue and you haven't shown any code to create a blank page (or any output) so it's hard to know where to start. You've only shown input steps.
xiangpang
Quartz | Level 8

the input file is like following:

 

---here, it is a blank line, then

name

_____________________________________________________________________________________________________________

 

 

~S={just=c preimage='A:\figure.png'}

_____________________________________________________________________________________________________________

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
  • 9 replies
  • 3147 views
  • 0 likes
  • 3 in conversation