Data visualization with SAS programming

Problem with Proc SGplot in a macro

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Problem with Proc SGplot in a macro

[ Edited ]

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.


Accepted Solutions
Solution
4 weeks ago
SAS Super FREQ
Posts: 3,475

Re: Problem with Proc SGplot in a macro

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


All Replies
PROC Star
Posts: 288

Re: Problem with Proc SGplot in a macro

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?

Contributor
Posts: 45

Re: Problem with Proc SGplot in a macro

@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...)
Super User
Posts: 17,775

Re: Problem with Proc SGplot in a macro

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;
Contributor
Posts: 45

Re: Problem with Proc SGplot in a macro

@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."
Super User
Posts: 17,775

Re: Problem with Proc SGplot in a macro

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

 

 

Contributor
Posts: 45

Re: Problem with Proc SGplot in a macro

@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.
Super User
Posts: 17,775

Re: Problem with Proc SGplot in a macro

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);
Super User
Posts: 10,476

Re: Problem with Proc SGplot in a macro

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);
Super User
Posts: 5,077

Re: Problem with Proc SGplot in a macro

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?

Super User
Posts: 17,775

Re: Problem with Proc SGplot in a macro

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.

 

Contributor
Posts: 45

Re: Problem with Proc SGplot in a macro

I've tried it without ods html close actually, but it still isn't working correctly.....
PROC Star
Posts: 1,230

Re: Problem with Proc SGplot in a macro

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; 

Contributor
Posts: 45

Re: Problem with Proc SGplot in a macro

@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"
SAS Super FREQ
Posts: 3,475

Re: Problem with Proc SGplot in a macro

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);
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 25 replies
  • 290 views
  • 6 likes
  • 7 in conversation