Desktop productivity for business analysts and programmers

ods html file = compound name with macro variable

Accepted Solution Solved
Reply
Contributor
Posts: 56
Accepted Solution

ods html file = compound name with macro variable

Hi!

My target is to put my everyday report to a certain folder, but the name of that html-file should include today-date - and here is some problem:

my code is:

%let cur_date_4=%sysfunc(putn(%sysfunc(today()), DDMMYYN4.));

/*%let report_name = %str(%')Sales report &cur_date_4.html%str(%');*/

%let report_name1=%str(Sales report);
%let report_name2=&cur_date_4;
%let report_name3=%str(.html);
%let reportname=%sysfunc(cat(&report_name1,&report_name2,&report_name3));

ods html path='C:\Users\U111\Documents\' file=&report_name style=minimal;

%my_report;

But it gives errors, and I don't know how to make it correct. Could anyone help me?


Accepted Solutions
Solution
‎03-19-2012 12:02 PM
Super User
Super User
Posts: 6,368

ods html file = compound name with macro variable

You should not need to use the CAT function to concatenate macro variables.  Just reference them where you need them.

%let reportname=&report_name1.&report_name2.&report_name3;

Shouldn't the FILE= option on the ODS statement use a quoted string?

  file="&report_name"

View solution in original post


All Replies
Solution
‎03-19-2012 12:02 PM
Super User
Super User
Posts: 6,368

ods html file = compound name with macro variable

You should not need to use the CAT function to concatenate macro variables.  Just reference them where you need them.

%let reportname=&report_name1.&report_name2.&report_name3;

Shouldn't the FILE= option on the ODS statement use a quoted string?

  file="&report_name"

Contributor
Posts: 56

ods html file = compound name with macro variable

Thanks - that method gave exactly the result I needed. Didn't met it (such joining macro variables - by '.') before...

Super User
Super User
Posts: 6,368

Re: ods html file = compound name with macro variable

The periods don't join the variables. They assist SAS in telling where the variable name ends.  It is not strictly needed in this case.

I better example for when you need to insert the period is when you want to have static characters right after the expanded macro variable, but the static characters could be interpretted as part of the macro variable's name.  For example if you wanted to append _SORTED to the end of dataset name.

%let dsname=source;

proc sort data=&dsname out=&dsname._sorted;

Without the period SAS would look for macro variable named DSNAME_SORTED.

Contributor
Posts: 56

ods html file = compound name with macro variable

Oh, now I've got it - '.' is just separator for SAS to read it right. Thanks for that remark - it's important)

Super Contributor
Posts: 394

ods html file = compound name with macro variable

I don't know what errors it gives, but I notice that you assigned the report name to reportname but spelled the macro variable as report_name in the ODS statement.

Contributor
Posts: 56

ods html file = compound name with macro variable

I'm sorry - when copied (by parts - because of useless comments), missed one string (-->):

%let cur_date_4=%sysfunc(putn(%sysfunc(today()), DDMMYYN4.));

/*%let report_name = %str(%')Sales report &cur_date_4.html%str(%');*/

%let report_name1=%str(Sales report);
%let report_name2=&cur_date_4;
%let report_name3=%str(.html);
%let reportname=%sysfunc(cat(&report_name1,&report_name2,&report_name3));

--> %let report_name = %str(%')&reportname%str(%');

ods html path='C:\Users\U111\Documents\' file=&report_name style=minimal;

%my_report;

and this code gives such error:

16 ods html path='C:\Users\U111\Documents\' file=&report_name style=minimal;

_____

22

76

ERROR 22-322: Syntax error, expecting one of the following: DYNAMIC, INCLUDE, NO_BOTTOM_MATTER, NO_TOP_MATTER, TITLE, URL.

ERROR 76-322: Syntax error, statement will be ignored.

_

22

200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

ERROR 200-322: The symbol is not recognized and will be ignored.

17 %my_report;

Contributor
Posts: 56

ods html file = compound name with macro variable

Some text displaying problems:

in first case 'style' is underlined, in second - 'ods' (the beginning of ods-string) is.

Esteemed Advisor
Posts: 7,299

ods html file = compound name with macro variable

Use double quotes on the line that is causing the error.  With single quotes the macro variable won't resolve.

Contributor
Posts: 56

ods html file = compound name with macro variable

Yes, I've tried new way of applying to macro variables and then used double quotes - and it worked just like I wanted. Thanks!

Maybe you know where can I find documentation with description of simple macro variables using (like manipulating with char,number macro variables, right macro variables resolving) for SAS EG? Primarily I met some too advanced articles mostly for SAS (base)....

SAS Super FREQ
Posts: 8,721

ods html file = compound name with macro variable

Hi:

  This is a good place to start:

http://www2.sas.com/proceedings/sugi28/056-28.pdf

   

  Also, if you search (Google) or go to support.sas.com and search or go to lexjansen.com and search for user group papers about using the SAS Macro facility, you should find a LOT of papers, tutorials and information about how the SAS Macro Facility works (including, but not limited to &macvar references and %macpgm invocations).

cynthia

Contributor
Posts: 56

ods html file = compound name with macro variable

Thank you, Cynthia!

☑ This topic is SOLVED.

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

Discussion stats
  • 11 replies
  • 1861 views
  • 7 likes
  • 5 in conversation