Som
Som

Reputation: 41

Can this run in a Macro?

I have been trying to resolve an issue and using a different approach to resolve it. I have created a macro to get actual value. The sql generates an HTML view with the values I need.

 %macro actualvalue();

 proc sql noprint;

 %do i=1 %to %wordcount(&fieldlist);

 Select %scan(&fieldlist,&i) into :actualvar separated by ' ' FROM TableA Where        
 IncidentItemId=%scan(&incidentitemlist,&i);

 %end;

 quit;

 %mend actualvalue;

However, the actualvar macro variable does not seem to capture the value. Is there something wrong in the way I am trying to initialize the macro variable or this cannot be performed inside a macro. Any thoughts on this would be appreciated.

Upvotes: 0

Views: 96

Answers (2)

Robert Penridge
Robert Penridge

Reputation: 8513

I think each time your do loop runs it is overwriting the previous value of actualvar. You need to use something like

select %scan(&fieldlist,&i) into :actualvar&i ...

Then afterwards print out values for &actualvar1 &actualvar2 etc... to check your results.

Upvotes: 1

Robbie Liu
Robbie Liu

Reputation: 1511

At least you need to put PROC SQL statement inside the DO loop, since your aim is running proc sql for multiple times

%do i=1 %to %wordcount(&fieldlist);
    proc sql noprint;
    Select %scan(&fieldlist,&i) into :actualvar separated by ' ' FROM TableA 
    Where IncidentItemId=%scan(&incidentitemlist,&i);
%end;

I don't see any problem regarding the rest though. Give it a test and report any error. I will modify this answer accordingly.

Upvotes: 0

Related Questions