sas macro warning

Reply
Super Contributor
Posts: 371

sas macro warning

Hello expert,

Please, a method to avoid the warning

 

%let v=( &v1, &v2);

 

%macro chech;

 

proc sql;

select w1,w2 into:v1,v2

from toto;

 

insert into toto

values&v;

quit;

%mend;

 

%check;

 

Super User
Posts: 19,052

Re: sas macro warning

We can't run this as is, it would definitely generate errors on our side since the macro variables aren't declared. 

 

What errors/warning are you trying to suppress?

Super User
Posts: 11,110

Re: sas macro warning

Copy the program and any warnings or errors from the log and paste into a code box opened by the {i} icon. The position of some characters of warnings or errors may be critical an pasting them into the forum without a code box removes the formatting.

 

When dealing with macros issues it also helps to use OPTIONS MPRINT.

Super User
Posts: 7,405

Re: sas macro warning

WHICH WARNING?

 

Linemoon, you should be able by now to post a question in an answerable way. Postings like this are disappointing to us, it seems our tips fall on poor soil.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,695

Re: sas macro warning

This is just overworking the problem from what I can see as:

data toto;
  set toto toto;
run;

Is effectively what you are trying to do, dupicates toto rows.  Your code will not work, the %let is outside the macro, and the select into is inside the macro.  Anyways, don't do it like that, just do the above datastep.

Super Contributor
Posts: 371

Re: sas macro warning

@ll: Thank you

You can see the code and the log below :

 

SAS PGM :

 

data toto;

w1=1;

w2='TY';

run;

%let v=(&v1., "&v2.");

%macro prog;

proc sql;

select max(w1)+1,w2 into :v1,:v2

from toto;

insert into toto

values&v;

quit;

%mend;

%prog;

 

 

SAS LOG

 

         %let v=(&v1., "&v2.");
WARNING: Apparent symbolic reference V1 not resolved.
WARNING: Apparent symbolic reference V2 not resolved.
        
        
         %macro prog;
        
          proc sql;
           select max(w1)+1,w2 into :v1,:v2
        
           from toto;
           insert into toto
            values&v;
          quit;
        
         %mend;
        
         %prog;
NOTE: The query requires remerging summary statistics back with the original data.
NOTE: 1 row was inserted into WORK.TOTO.

Super User
Posts: 7,405

Re: sas macro warning

[ Edited ]

You're creating v1 and v2 in a macro, so they are local to the macro. Use

%global v1 v2;

in the macro to put them into the global macro variable table.

And call the macro before using v1 and v2.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 371

Re: sas macro warning

@ll: Thank you.

I know that. I do not need them to be "global"

For a global parameter , I need

%let v =(&v1,"&v2");

for avoid that's worning, I think  about mask function

Super User
Super User
Posts: 6,842

Re: sas macro warning

Do you want to assign the literal string '&v1' as part of the value of the macro variable V?  If so the easiest way is to use a data step and call symputx() function.

data _null_;
   call symputx('V','(&v1,"&v2")');
run;
Super Contributor
Posts: 371

Re: sas macro warning

@Tom : Thank you tom that's exact, there is "no warning " in the output.

But I need one line code and macro-variable indexed, f1, f2,...fn

%let f1=(&v1, "&v2");

 

%let fn=(&m1,&y2,"& h");

 

 

Respected Advisor
Posts: 4,131

Re: sas macro warning

@LineMoon

Then you need to create and populate &f1 to &fn as global variables inside your macro.

Super User
Posts: 19,052

Re: sas macro warning

What are you expecting this line to do

 

values&v

 

You expect that to resolve to?

 

values (&v1, &v2)

 

If so, I don't think that logic is quite correct. 

Super User
Super User
Posts: 6,842

Re: sas macro warning

What is the larger problem that you are trying to solve? Perhaps there is an easy way that does not involve so many macro variables.

If the goal is to move data around then having the data in data sets is probably going to be much easier. It will also be more accurate since you can lose precision converting data into text to store in macro variables.

 

Super User
Super User
Posts: 6,842

Re: sas macro warning

[ Edited ]

Why are you using macro variables?

Can't you just replace these two statements:

select max(w1)+1,w2 into :v1,:v2
  from toto
;
insert into toto
values&v
;

with this one statement that does not need macro variables at all?

insert into toto
select max(w1)+1,w2
from toto
;

If SAS complains about reading and writing from the same table then introduce a temporary table.

create table temp as 
select max(w1)+1 as w1,w2
from toto
;
insert into toto
select * from temp
;
Super Contributor
Posts: 371

Re: sas macro warning

@Tom :Thank you,

I prefere   Fi=(&v1,"&v2.") and values&Fi.

because Fi can change

I can have

Fj=(&v1,"&v2",'test1',"&country",'',.);

 

 

 

 

 

 

Ask a Question
Discussion stats
  • 15 replies
  • 230 views
  • 1 like
  • 7 in conversation