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 ?
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 ?
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
@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.
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.
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.
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;
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?
the input file is like following:
---here, it is a blank line, then
name
_____________________________________________________________________________________________________________
~S={just=c preimage='A:\figure.png'}
_____________________________________________________________________________________________________________
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.