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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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.

View solution in original post

25 REPLIES 25
collinelliot
Barite | Level 11

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?

Leon27607
Fluorite | Level 6
@collinelliot I've tried it even without ods html close, and by "not running" I mean if I run the macro, then try to call the macro in a statement using "%plots(input, cholinevar, Response, SNP, Title);" for some reason SAS just does nothing....(like nothing literally happens... I don't see it trying to "process" anything and I don't see anything in my log...)
Reeza
Super User

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;
Leon27607
Fluorite | Level 6
@Reeza, if I run it outside the macro, i mentioned it works and I get "
NOTE: Writing HTML Body file: sashtml.htm
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 1.85 seconds
cpu time 0.81 seconds

NOTE: Listing image output written to C:\Users\Name\Desktop\Projects\SGPlot1.png.
NOTE: There were 796 observations read from the data set DATA2.INPUTDATA."
Reeza
Super User

Where's the log from MPRINT/SYMBOLGEN. Why isn't your code showing in the log or did you just not post it?

 

 

Leon27607
Fluorite | Level 6
@Reeza That was me running it OUTSIDE the macro so Mprint/symbolgen didn't show anything. If I try to use those and run the macro itself... as I mentioned I think SAS is not working properly. Nothing shows up in my log as though my code didn't even run. The thing is if I try to close SAS, only upon the moment I actually try to exit it I'll see an error message that says my Macro has an invalid expression or something(It's hard to tell what it really says in that split second). I've tried restarting SAS and my computer but it still doesn't fix this problem. I'm just wondering if my SAS is just "Broken" or if there's really something wrong with my code. I'm using SAS 9.4.
Reeza
Super User

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);
ballardw
Super User

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);
Astounding
PROC Star

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?

Reeza
Super User

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.

 

Leon27607
Fluorite | Level 6
I've tried it without ods html close actually, but it still isn't working correctly.....
Quentin
Super User

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; 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Leon27607
Fluorite | Level 6
@Quentin
Yeah... it's like trying to run the macro "plots" breaks my SAS because I don't get anything from proc print data = sashelp.class

Everything will work before I try to create the plots macro. For any code before this step, the only thing I did was reference the libraries. As for my SAS client I'm not exactly sure because the name of the program is literally just "SAS for Window". SAS 9.4 TS Level 1M3.

Also @ballard yes I know they aren't exactly the same thing but I meant even if I used the same "X" and "Y" SAS just isn't cooperating with the "plots" macro I generate.

Oh also an additional detail seems like the Error(upon closing SAS) that I get says...

"ERROR: Macro parameter contains syntax error"
Rick_SAS
SAS Super FREQ

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);

SAS Innovate 2025: Register Now

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!

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
  • 25 replies
  • 4751 views
  • 6 likes
  • 7 in conversation