Data visualization with SAS programming

Saving Proc GCHart graphs as an image file

Reply
Contributor
Posts: 58

Saving Proc GCHart graphs as an image file

So my code seem to work, but it doesn't seem to save my graph as an image file in the directory I specified. I am unsure how to troubleshoot this and was wondering if anyone can give me some suggestions.

So when I goto C:\Graphs, there is nothing there. Does ODS Graphics not work with Proc Gchart? I used the exact ODS graphics and ODS listing code with Proc SGpanel and it works

%macro graph (var);

DATA _null_;

  SET fich;

  array vars(*) &var;

  DO i=1 TO dim(vars);

  call symput("mvNAME"||strip(i),strip(vname(vars(i))));

  call symput("mvLAB"||strip(i),strip(vlabel(vars(i))));

  END;

  call symput("mvNB",strip(dim(vars)));

RUN;

%DO b=1 %TO &mvNB;

Title "&&mvLAB&b";

ods graphics on/reset=all imagename="&&mvNAME&b" width=27.8cm height=14cm;

ods listing style=custom2 gpath="c:\Graphs";

proc gchart data=fich;

  pie &&mvNAME&b /     DISCRETE VALUE=OUTSIDE

                 PERCENT=OUTSIDE SLICE=OUTSIDE;

  run; quit;

ods graphics off;

%end;

%mend graph;

%graph(CS1-CS6);

Grand Advisor
Posts: 16,393

Re: Saving Proc GCHart graphs as an image file

GChart does not use ODS, the SG procedures do.

I'm not sure how to save your graphics either Smiley Sad

Contributor
Posts: 58

Re: Saving Proc GCHart graphs as an image file

Ah that is why. I have to see if I can create a pie chart with SG procedures.

Grand Advisor
Posts: 9,748

Re: Saving Proc GCHart graphs as an image file

If you send your HTML output to a specific folder and use the NAME option you will get a PNG file with desired name:

ods html path="C:\graphs";

proc gchart data=fich;

  pie &&mvNAME&b /     DISCRETE VALUE=OUTSIDE

                 PERCENT=OUTSIDE SLICE=OUTSIDE name=&&mvNAME&b;

  run; quit;

You should be able to make all of your graphs with one pass through the data:

proc gchart data=fich;

%DO b=1 %TO &mvNB;

  pie &&mvNAME&b /     DISCRETE VALUE=OUTSIDE

                 PERCENT=OUTSIDE SLICE=OUTSIDE name=&&mvNAME&b;

  run;

%end;

quit;

though that won't address your potential TITLE issue.

Contributor
Posts: 58

Re: Saving Proc GCHart graphs as an image file

The title in the graph would be nice, but not essential... Ssince I will be copying and pasting all of these pie chart (82 of them) into an online survey.. I am hoping to have the title in the image itself just as another Quality check to make sure it's the right one.

I'll try this tomorrow and report back if it works.

Grand Advisor
Posts: 16,393

Re: Saving Proc GCHart graphs as an image file

Why not output to ODS RTF then?

Grand Advisor
Posts: 16,393

Re: Saving Proc GCHart graphs as an image file

If you're on SAS 9.4 you can use SGTemplate/Render:

SAS(R) 9.4 Graph Template Language: Reference, Fourth Edition

Contributor
Posts: 58

Re: Saving Proc GCHart graphs as an image file

Thanks sadly on 9.2

Post a Question
Discussion Stats
  • 7 replies
  • 492 views
  • 6 likes
  • 3 in conversation