BookmarkSubscribeRSS Feed
venkatard
Calcite | Level 5

ods &styl file='C:\Users\sas\Desktop\discharge_print.xml';

Does the above code work. I am creating a macro variable to automate the output template.

5 REPLIES 5
AncaTilea
Pyrite | Level 9

Hi.

This is a very ambiguous question.

I guess it depends on what values you give to the macro variable &styl.

If it takes the values tagsets.excelxp, then yes, it works

but if it takes the value default (which may be one of the style you may want to use...)

So, what do you want to do?

The code below is a macro that creates an XML file using different styles (default, normal, statistical...)

%let path = your_path

%macro print(styl = );

    ods tagsets.excelxp file = "&path.\discharge_print_&styl..xml" style= &styl. ;

    proc print data = sashelp.class;where sex = "F";

    run;

%mend print;

%print(styl = normal);

%print(styl = default);

Not sure what you want.

venkatard
Calcite | Level 5

I am sorry for confusing.

ods &styl file='C:\Users\sas\Desktop\discharge_print.&styl';


and when calling macro variable %sty(styl=pdf);


That means i am opting a pdf output.


Does this logic work?

Linlin
Lapis Lazuli | Level 10

Hi,

You have to use double " " when macro variables are involved.

ods &styl file='C:\Users\sas\Desktop\discharge_print.&styl ';

AncaTilea
Pyrite | Level 9

So, yes it would work;

%macro print(styl = );

    ods &styl. file = "&path.\discharge_print.&styl."  ;

    proc print data = sashelp.class;where sex = "F";

    run;

   ods &styl. close;

%mend print;

%print(styl = pdf);

%print(styl = html);

Please note the "ods &styl. close" statement as well.

And yes, you should always use double quotes instead of single quotes in a macro.

Good luck,

Anca.

Cynthia_sas
SAS Super FREQ

Hi:

  In my opinion, &STYL is a confusing name to use for the macro variable. Here's why. When you have an ODS "sandwich"

ods <destination> file="somefile.ext" style=<style>;

...more code ...

ods <destination> close;

the <destination> should be specified as:

ods html

ods pdf

ods rtf

ods tagsets.excelxp

ods msofice2k

etc, etc.

None of those destinations is a STYLE definition name. The <destination> used by ODS is different from the STYLE definition used by ODS. for example, there is no style called PDF and there is no style called HTML or TAGSETS.EXCELXP... those are all destinations.

  A less confusing name for the macro variable would be &DEST, which would then allow you to use &STYL to change the style definition used for your output. Another possible macro variable might be &EXT, so that if you use a destination like MSOFFICE2K, you can specify the correct .HTML extension. Or you can specify a different style definition for each destination, or based on the destination, you can use a %IF to create a macro variable for other options (&OTHEROPT).

  I used some color coding in the program below to give you the general idea of the possible use for 3 different macro variables. I didn't do color coding for every macro variable reference, but there should be enough to convey the general concept of the difference between ODS destination, ODS style and the file extension for the file you are creating.

  This is just my .02 on the design of the macro program and naming the macro variables so they accurately reflect which code piece you are generating: the destination name, the file extension (which does NOT always match the destination name) and the style specification (which again, does not always match the destination name).

cynthia

%macro alt(dest=, ext=, styl= );
  ods listing close;
  option nodate number pageno=1;
   
  %if %upcase(&dest)=TAGSETS.EXCELXP %then %do;
      %let otheropt = options(embedded_titles='yes');
  %end;
  %if %upcase(&dest)=PDF %then %do;
      %let otheropt = notoc;
  %end;
  %else %let otheropt=;
    
  ods &dest file = "c:\temp\use_&dest._&styl..&ext
            style=&styl &otheropt ;
    title "Using &dest with &styl style to create &ext type of file";
    proc print data = sashelp.class;
       where sex = "F";
    run;
  ods &dest close;
%mend alt;
 
%alt(dest=html, styl=htmlblue, ext=html)
 
%alt(dest=pdf, styl=journal, ext=pdf)
 
%alt(dest=rtf, styl=analysis, ext=rtf)
 
%alt(dest=msoffice2k, styl=normal, ext=html)
 
%alt(dest=tagsets.excelxp, styl=sasweb, ext=xml)

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
  • 5 replies
  • 1108 views
  • 0 likes
  • 4 in conversation