apologies if my title was confusing to read, but I am not aware of how else to describe it briefly.
I am trying to call a variable from a table that is a macro variable (The table is a macro variable)
My macro looks like this:
%macro genre_analysis(table1=,table2=,genre=,genre1=);
proc sql;
create table &table1 as
select id, original_title, genres, revenue
from genres_revenue
where genres_revenue.genres like &genre
and revenue is not null
group by id
having revenue ne 0
;
quit;
proc sql;
create table &table2 as
select avg(revenue) as Average format=dollar16.2, median(revenue) as Median format=dollar16.2, std(revenue) as std format=dollar16.2
from &table1;
quit;
Everything works fine until I get to this part of the macro:
proc sql;
title "Revenue Stats by Genre";
insert into genre_summary
set Genre=&genre1,
average=&table2.average,
median=&table2.median,
std=&table2.std;
%mend genre_analysis;
I am trying to insert a row into a table I create outside of the macro. But using "&table2.average" and the 2 others that starts with "&table2" does not call the variables from the table I created in the macro.
For example:
%genre_analysis(table1=horror_revenue,table2=horror_revenue_stats,genre='%Horror%',genre1='Horror')
Returns:
NOTE: Table WORK.HORROR_REVENUE created, with 725 rows and 4 columns.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
NOTE: Table WORK.HORROR_REVENUE_STATS created, with 1 rows and 3 columns.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
ERROR: Character expression requires a character format.
ERROR: Character expression requires a character format.
ERROR: Character expression requires a character format.
ERROR: It is invalid to assign a character expression to a numeric value using the SET clause.
ERROR: It is invalid to assign a character expression to a numeric value using the SET clause.
ERROR: It is invalid to assign a character expression to a numeric value using the SET clause.
**ERROR: The following columns were not found in the contributing tables:
horror_revenue_statsaverage, horror_revenue_statsmedian, horror_revenue_statsstd.**
I have been focusing on the Error that I starred, as I believe that is where the issue is.
I tried using a "from" clause but that does not seem to work either.
Any assistance or suggestions would be appreciated!
title
above theinsert
– Richard