BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

6 REPLIES 6
michtka
Fluorite | Level 6

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);

Jagadishkatam
Amethyst | Level 16

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
Patrick
Opal | Level 21

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

michtka
Fluorite | Level 6

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.

Patrick
Opal | Level 21

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;

Patrick
Opal | Level 21

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);

.....

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 5095 views
  • 4 likes
  • 3 in conversation