I am attempting to create a macro that will average the variables in column "Assignment1" but I am unable to get it to work.
Grades.csv
Name | Gender | Assignment1 | Assignment2 | Assignment3 | Assignment4 |
Aldrin | M | 98 | 56 | 81 | 94 |
Becky | F | 100 | 54 | 100 | 99 |
Carl | M | 95 | 69 | 48 | 93 |
Daphne | F | 57 | 79 | 82 | 46 |
Eriksen | M | 83 | 98 | 72 | 85 |
Frank | M | 46 | 89 | 78 | 67 |
Gary | M | 86 | 83 | 72 | 87 |
Hobbs | M | 68 | 57 | 82 | 73 |
Isabella | F | 98 | 85 | 88 | 63 |
Jeanette | F | 74 | 92 | 78 | 48 |
Kevin | M | 81 | 61 | 62 | 87 |
Lily | F | 49 | 87 | 52 | 97 |
Mickey | M | 66 | 63 | 75 | 75 |
Nora | F | 66 | 47 | 42 | 88 |
Oprah | F | 92 | 86 | 52 | 59 |
Patrice | F | 51 | 100 | 79 | 75 |
Quinn | F | 60 | 77 | 42 | 84 |
Robin | F | 54 | 41 | 89 | 65 |
Stella | F | 61 | 50 | 53 | 89 |
Tracy | F | 54 | 72 | 71 | 86 |
Ursula | F | 80 | 80 | 99 | 70 |
Victoria | F | 52 | 59 | 46 | 84 |
Wendy | F | 50 | 47 | 64 | 63 |
Xander | M | 94 | 45 | 66 | 91 |
Yasmine | F | 84 | 68 | 77 | 93 |
Zoey | F | 64 | 40 | 71 | 71 |
The code I have is :
%macro average(variable=);
proc means data=work.grades mean;
var &variable;
run;
%mend;
%average(variable=Assignment1);
I am using SAS University addition and I cannot figure out what I am doing wrong. Thank you for any help. I am am new to SAS.
haven't you miss the output statement ?
%macro average(variable=);
proc means data=work.grades mean;
var &variable;
output out=mean_of_&variable;
run;
%mend;
%average(variable=Assignment1);
The SAS log is the #1 diagnostic tool (also see Maxim 2), so please post the log of your macro call; use the same posting method ({I} button) that you used for posting the code.
As @Astounding already said, the code as such looks good.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.