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

How do I create the macros I want to use in the footnote described below if I want to base the macros on the values of the movies, pop, and awardnum variables? Is this possible or is there another way to create a footnote with the values of those variables? I tries #BYVAR and #BYVAL also and it didn't work. 

 

proc sql;

create table hw3.actor as

select id, title, actor, count(title) as movies, avg(popularity) as pop, count(awards) as awardnum

from hw3.films3

where id=&id;

quit;

 

proc print data=hw3.actor;

where id=&id;

var title;

title "Actor Name: &actor10";

footnote "&movies &pop &awardnum";

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Take a look at @s_lassen 's answer to your question yesterday.  His first code block shows how to use SQL into:  to create macro vars.

https://communities.sas.com/t5/SAS-Programming/Macro-Beginner/m-p/633338

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

I can't try this without your data, but it seems like your SQL isn't right. It seems like you want

 

group by id,title,actor

in your SQL in order to get the counts and averages.

 

Then, when you print BY ID; the variables #BYVAL and #BYVAR ought to work.

--
Paige Miller
matoma
Obsidian | Level 7

Picture1.png

My proc sql is giving me kind of what I want in the sense that it has the total number of movies, the average popularity, and the number of awards. Its just showing up 7 times for each movie title and id. I guess what I'm trying to do is take the values of 7 for movies, 57.28 for pop and 7 for awards and put it into a footnote. 

PaigeMiller
Diamond | Level 26

Yes, but if you do the PROC PRINT with the BY statement, then FOOTNOTE with #BYVAR and #BYVAL works fine.

 

by id movies pop awardnum;
--
Paige Miller
Quentin
Super User

Take a look at @s_lassen 's answer to your question yesterday.  His first code block shows how to use SQL into:  to create macro vars.

https://communities.sas.com/t5/SAS-Programming/Macro-Beginner/m-p/633338

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Tom
Super User Tom
Super User

But the code you posted has neither a BY statement nor any use of the #BYVAL() tag.

proc sql;
create table hw3.actorS as
  select id, title, actor
       , count(title) as movies
       , avg(popularity) as pop
       , count(awards) as awardnum
from hw3.films3
group by id
order by id
;
quit;

proc print data=hw3.actorS;
  by id actor movies pop awardnum;
  pageby id;
  var title;
title "Actor Name: #byval(actor)";
footnote "Movies #byval(movies) Popularity #byval(pop) Awards #byval(awardnum)";
run;
title;
footnote;

 Notice that there is no need for defining a macro or for using any macro varaibles.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 820 views
  • 0 likes
  • 4 in conversation