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

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 603 views
  • 0 likes
  • 4 in conversation