BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

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;

 

15 REPLIES 15
Reeza
Super User

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?

ballardw
Super User

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.

Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

LineMoon
Lapis Lazuli | Level 10

@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.

Kurt_Bremser
Super User

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.

LineMoon
Lapis Lazuli | Level 10

@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

Tom
Super User Tom
Super User

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;
LineMoon
Lapis Lazuli | Level 10

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

 

 

Patrick
Opal | Level 21

@LineMoon

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

Reeza
Super User

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. 

Tom
Super User Tom
Super User

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.

 

Tom
Super User Tom
Super User

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
;
LineMoon
Lapis Lazuli | Level 10

@Tom :Thank you,

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

because Fi can change

I can have

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

 

 

 

 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 1073 views
  • 1 like
  • 7 in conversation