-1

I refer here to the the issue addressed 6 years ago in "SAS GRAPH and multiple charts, more meaningful names?" To me this issue needs a solution. I need to generate one chart by indicator (2) and country (27). The index is 1,3,5,7,9,...,107. Please try to find the file/worksheet (png/xls) for country x and indicator y. Good luck! Can somebody help me? Maybe the person who addressed the issue at that time found a solution (I really hope it)? Many thanks!

Below you have an example using sashelp library. It creates Picture1.png, Picture3.png and Picture5.png. Instead of this, I would like to have PictureIBM.png, PictureIntel.png and PictureMicrosoft.png.

proc sort data=SASHELP.STOCKS out=testfile; by stock date; run;
data testfile; set testfile;
by stock  ;
retain n;
if first.stock then n=0; else n=n+1;
if n le 5;
run;


ods listing gpath='write the path' ;
ods listing /*style = styles.new_font   */
    gpath='/ec/prod/1eusilc/flashestimates/FLIPI/3_Output/FE/PERFORMANCE/overall 2022/TIME SERIES' ;


ods graphics on / 
      width=14in height=10in
      outputfmt=gif
      imagemap=on
      imagename="Picture"
      border=off  reset=index ;


proc sgplot data=testfile noborder noopaque nowall  dattrmap=DATTRMAP  
title "write the title";
by stock ;
highlow x=date low=low high=high / type=bar   ;
scatter x=date y=close   ;
xaxis type=discrete;
run;
  • I have added an answer to the original question [here](https://stackoverflow.com/questions/38949236/sas-graph-and-multiple-charts-more-meaningful-names/74057505#74057505) – shaun_m Oct 13 '22 at 14:32
  • Thank you but I do not understand how can I adapt your solution to proc sgplot. I use ods listing; ods graphics and proc sgplot. In sgplot I have two highlow statements and 1 scatter statement. – Mihaela Nicolescu Agafitei Oct 13 '22 at 15:12
  • You don't show your code or an example or the issue. A solution mentioned in the linked post is to use macro's which gets around this entirely. – Reeza Oct 13 '22 at 15:16
  • I can not copy/paste SAS code as the text is too long (even simplified)) – Mihaela Nicolescu Agafitei Oct 13 '22 at 15:18
  • You can make a simplified example of the issue using a data set from sashelp. – Reeza Oct 13 '22 at 15:18
  • And I never said "there is no reason to have specific names", I said, " I've fortunately never had a reason to have specific file names." – Reeza Oct 13 '22 at 15:25
  • I will try to use sashelp and come back! I am sorry for keeping in mind only the second part of the phrase! I am really blocked (and nervous) with this issue that keep me far from other much more important issues. Many thanks for trying to help me. – Mihaela Nicolescu Agafitei Oct 13 '22 at 15:30
  • FYI the reason I've never had to worry about the file names is because I usually put graphics straight from SAS into a Word/PPT/PDF document as necessary for reporting. – Reeza Oct 13 '22 at 19:50

1 Answers1

0

Here are two ways to do this, one uses the #byval as indicated in the previous solution and which you used in title but not the file name for some reason.

First make fake data:

data prdsummary;
    set sashelp.prdsale;
    where year=1993 and (country="GERMANY" or country="CANADA") and region="EAST" 
        and division="CONSUMER" and
    (product="SOFA" or product="TABLE" or product="BED");
run;

proc sort data=prdsummary;
    by country;
run;

Then use #BYVAL. However, if you run this code multiple times, SAS does not overwrite the previous files, it adds a 1 to the filename instead. So you need to make sure that the files don't already exist. There may be an option to control this feature, I'm unsure at the moment.


ods listing gpath='/home/fkhurshed/Demo1/';
title 'Graph for #byval1';
ods graphics / imagename="Country #byval1";

proc sgplot data=prdsummary;
    by country;
    vbar prodtype / group=product response=actual groupdisplay=stack;
run;

A second workaround is to use a macro instead and control the name explicitly.

*explicitly control the names via macro looping;
ods listing gpath='/home/fkhurshed/Demo1/';


%macro generate_country_graph(country=);
    ods graphics / imagename="Graphic for &Country.";

    proc sgplot data=prdsummary;
        where country="&country";
        vbar prodtype / group=product response=actual groupdisplay=stack;
    run;

%mend;

data _null_;
    set prdsummary;
    by country;

    if first.country then
        do;
            str=catt('%generate_country_graph(country=', country, ');');
            call execute(str);
        end;
run;
Reeza
  • 20,510
  • 4
  • 21
  • 38