Help using Base SAS procedures

macro (Warning:apparent symbol not resolved)

Accepted Solution Solved
Reply
Super Contributor
Posts: 301
Accepted Solution

macro (Warning:apparent symbol not resolved)

Hi all, I have the next error message in this code:

WARNING: Apparent symbolic reference RECORD1 not resolved.

WARNING: Apparent symbolic reference RECORD2 not resolved.

WARNING: Apparent symbolic reference RECORD3 not resolved.

WARNING: Apparent symbolic reference RECORD4 not resolved.

Can you tell me what I am doing wrong? Thanks. V

****piece of code;

data have;

input records;

datalines;

1

2

3

4

;

run;

%macro test(n=);

data  want&n.;

set have (obs=&n.);

if n=1 then call symput("record1",records);

if n=2 then call symput("record2",records);

if n=3 then call symput("record3",records);

if n=4 then call symput("record4",records);

run;

%mend test;

%test(n=1);

%test(n=2);

%test(n=3);

%test(n=4);

%put &record1 &record2 &record3 &record4;


Accepted Solutions
Solution
‎10-27-2013 11:59 PM
Respected Advisor
Posts: 4,173

Re: macro (Warning:apparent symbol not resolved)

You create the macro variables within a  macro and so they have a scope of local.

You need to add the following inside your macro:

%global &record1 &record2 &record3 &record4;

I would also add a %let statement to initialise the macro vars so that you don't have "left over" populated macro vars from previous runs.

If I understand correctly what you're trying to do then you should also use "&n" instead of "n" in your if condition.

if &n=1 then call symput("record1",records);

...and as only one of the conditions will be true you should also use an else:

if &n=1 then call symput("record1",records);

else if &n=2 then call symput("record2",records);

.....

View solution in original post


All Replies
Super Contributor
Posts: 301

Re: macro (Warning:apparent symbol not resolved)

Sorry, my mistake....but still does not work...any help? Thanks.

if &n.=1 then call symput("record1",records);

if &n.=2 then call symput("record2",records);

if &n.=3 then call symput("record3",records);

if &n.=4 then call symput("record4",records);

Trusted Advisor
Posts: 1,137

Re: macro (Warning:apparent symbol not resolved)

data have;

input records;

datalines;

1

2

3

4

;

run;

options symbolgen mprint mlogic;

%macro test(n=);

%global record&n.;

data  want&n.;

set have (firstobs=&n. obs=&n.);

call symputx("record"||left(put(&n.,2.)),records);

run;

%mend test;

%test(n=1);

%test(n=2);

%test(n=3);

%test(n=4);

%put &record1 &record2 &record3 &record4 ;

Thanks,

Jagadish

Thanks,
Jag
Respected Advisor
Posts: 4,173

Re: macro (Warning:apparent symbol not resolved)

Answer already provided in my initial post. Read it all.

Super Contributor
Posts: 301

Re: macro (Warning:apparent symbol not resolved)

Thanks guys for your reply,

Dear Patrick, several questions:

What is the difference of using a) or b),

this b) option could work in my code also?

a)if &n=1 then call symput("record1",records);


b)%if &n=1 %then call symput("record1",records);


Thanks in advance,


V.

Respected Advisor
Posts: 4,173

Re: macro (Warning:apparent symbol not resolved)

In the SAS Macro doc and I believe also in the SAS Concepts doc is a detailed description of how the SAS Macro and SAS Language processors interact. It's very important to understand this.

As for your question:

Lets assume "&n" has a value of "2":

a) resolves on macro level "&n". The SAS language sees then: if 2=1 then call symput("record1",records);

b) tests the macro %if condition on macro level. As the condition is not true the SAS language "sees" nothing. If the condition would be true the SAS language would see: call symput("record1",records);

An alternative way of coding only creating the macro variable for the current value of "&n":

%macro test(n=);

  %global record&n;

  data  want&n.;

     set have (obs=&n.);

     call symputx("record&n",records);

  run;

%mend test;

Solution
‎10-27-2013 11:59 PM
Respected Advisor
Posts: 4,173

Re: macro (Warning:apparent symbol not resolved)

You create the macro variables within a  macro and so they have a scope of local.

You need to add the following inside your macro:

%global &record1 &record2 &record3 &record4;

I would also add a %let statement to initialise the macro vars so that you don't have "left over" populated macro vars from previous runs.

If I understand correctly what you're trying to do then you should also use "&n" instead of "n" in your if condition.

if &n=1 then call symput("record1",records);

...and as only one of the conditions will be true you should also use an else:

if &n=1 then call symput("record1",records);

else if &n=2 then call symput("record2",records);

.....

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1193 views
  • 4 likes
  • 3 in conversation