BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
need_some_help
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

11 REPLIES 11
Tom
Super User Tom
Super User

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"

need_some_help
Calcite | Level 5

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

Tom
Super User Tom
Super User

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.

need_some_help
Calcite | Level 5

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

Tim_SAS
Barite | Level 11

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.

need_some_help
Calcite | Level 5

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;

need_some_help
Calcite | Level 5

Some text displaying problems:

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

art297
Opal | Level 21

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

need_some_help
Calcite | Level 5

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)....

Cynthia_sas
SAS Super FREQ

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

need_some_help
Calcite | Level 5

Thank you, Cynthia!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 11 replies
  • 4564 views
  • 7 likes
  • 5 in conversation