I'm having trouble with this simple macro using SGplot, when I try to run it, SAS just doesn't do anything... it won't run through my code although I can still "Break" my submitted statements. It doesn't say that it's "running" it though.
%Macro plots(data, cholinevar, response, SNP, title);
PROC sGPLOT DATA = &data noautolegend;
vbar &cholinevar._4 / response = &response stat = mean group = &SNP groupdisplay = cluster limitstat = stderr ;
title "&title";
run;
PROC sGPLOT DATA = &data noautolegend;
reg x = &cholinevar y = &response /group = &SNP clm ;
title "&title";
run;
%mend plots;
%plots(input, cholinevar, Response, SNP, Title);
I don't understand why this code isn't running correctly, I've tried restarting SAS and my computer and it still won't run. The thing is, the first time I tried to run it, it worked but now it's not working. Running the pieces of the plot outside the macro can also work fine...
PROC sgplot DATA = input noautolegend;
reg x = X y = Y /group = SNP clm ;
title "Title";
run;
So yeah I don't understand why running the same thing outside the macro works fine but trying to use the macro causes SAS to hang and seem to do nothing.... Trying to rerun the "plots" macro will say that it's currently in use so I can't edit it unless I chose to break my submitted statements.
Edit 1: Figured out the error message when I close SAS, it'll say "Error: Macro parameter contains syntax error"
The thing is this error message does NOT show up when I'm trying to implement the macro and only shows up if I try to quit SAS.
By the way, the code you posted has a syntax error:
%plots(data2.inputdataremoved, choline_f2a, WRPM_ss, snp180, rs8016556_C(FDR=0.0403323974);
Put an extra closing parenthesis before the semicolon.
What do you mean by "not running?" Is there an error in the log? Might it be related to the "ods html close;" when I don't see anywhere where you open the html destination to output the plot?
Run the macro with MPRINT/SYMBOLGEN on and please run the SGPLOT code EXACTLY in an non macro version version and post the log.
option symbolgen mprint;
Where's the log from MPRINT/SYMBOLGEN. Why isn't your code showing in the log or did you just not post it?
Well, test the simplest case.
What happens if you run the following code - and please post your log from it. If it works, start adding back your data and then adding your components of code ONE AT A TIME until either it doesn't or it works the way you want.
options mprint symbolgen;
ods html;
%Macro plots(data, cholinevar, response, SNP, title);
PROC sGPLOT DATA = &data noautolegend;
vbar &cholinevar. / response = &response stat = mean ;
title "&title";
run;
%mend plots;
%plots(sashelp.class, sex, weight, SNP, Title);
The "outside" code you show:
PROC sgplot DATA = input noautolegend;
reg x = X y = Y /group = SNP clm ;
title "Title";
run;
Is NOT the same as the macro code would generate. The similar code section:
PROC sGPLOT DATA = &data noautolegend; reg x = &cholinevar y = &response /group = &SNP clm ; title "&title"; run;
Would resolve to
PROC sGPLOT DATA = input noautolegend; reg x = cholinevar y = response /group = SNP clm ; title "title"; run;
when using the call
%plots(input, cholinevar, Response, SNP, Title);
Do you have any other output destinations available?
At the end of the first execution, you issue:
ods html close;
So where is the output supposed to go the next time?
The log will tell you if all Destinations are closed.
WARNING: No output destinations active.
NOTE: There were 19 observations read from the data set
SASHELP.CLASS.
I think the problem has to be somewhere earlier, in code you haven't shown. Maybe unmatched quotes. Or an unclosed /* comment block. Or unclosed %macro statement.
Which SAS client are you using? (Display Manager, EG, SAS Studio)? EG (and I suspect SAS Studio) end with submitting a magic string that "fixes" unmatched quotes and similar problems, but in my experience this sometimes makes the problem harder to detect.
Your code itself looks fine. Below I added a step to make some sample data, and commented out the ODS HTML CLOSE inside the macro. It runs fine for me; I get two plots. I would try starting a new session, and submitting exactly this code, to see if you get a result.
data input; do snp=1 to 3; do cholinevar=1 to 5; cholinevar_4=cholinevar; response=ranuni(0)*100; output; end; end; run; %Macro plots(data, cholinevar, response, SNP, title); PROC sGPLOT DATA = &data noautolegend; vbar &cholinevar._4 / response = &response stat = mean group = &SNP groupdisplay = cluster limitstat = stderr ; title "&title"; run; PROC sGPLOT DATA = &data noautolegend; reg x = &cholinevar y = &response /group = &SNP clm ; title "&title"; run; ***ods html close; %mend plots; %plots(input, cholinevar, Response, SNP, Title);
If you don't get any result from that, I would try a new session, and see if you can get anything from proc print data=sashelp.class;run;
Let's have you run it on data that we can all access. Please exist SAS, then start SAS again and run the following program:
%Macro plots(data, cholinevar, response, SNP, title);
PROC sGPLOT DATA = &data noautolegend;
vbar &cholinevar. / response = &response stat = mean group = &SNP groupdisplay = cluster limitstat = stderr ;
title "&title";
run;
PROC sGPLOT DATA = &data noautolegend;
reg x = &cholinevar y = &response /group = &SNP clm ;
title "&title";
run;
%mend plots;
%plots(sashelp.class, age, weight, sex, My Plot Title);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.