DATA Step, Macro, Functions and more

SAS Macro with Title Statement

Reply
Occasional Contributor
Posts: 17

SAS Macro with Title Statement

Hello,

 

I am a student in a beginner's class.

 

I've been asked to create SAS code to generate the following output using SAS macros:

Capture.JPG

 

This is what I have so far as my output:

Capture.JPG

The problem I am facing is that I cannot get the date to insert correctly.

My guidelines provided are as follows:

        i)  Use the %Let SAS Macro with a SAS Macro name.  (You will not need more than 3 %let statements.)

       ii)  Use the system generated SAS Macros for your Day and Date in title

      iii)  To create both titles on same output (second table), you will have to use Title1 and Title2 statements.

%Let BeginDt = DATEJUL( yyddd );
%Let Enddt = DATEJUL( yyddd );
%Let TitleYr = DATEJUL( yyddd );
proc print data=wine.winedata noobs label;
	where origin='France';
	var Varietal Campaign past_peak cases_purchased;
	title1 'France Monthly Sales by Product';
	title2 "Report Issued on &titleyr";
run;

Any ideas on what I am doing wrong that the date will not appear correctly?

Thank you, in advance!

Super User
Posts: 5,518

Re: SAS Macro with Title Statement

A couple of concepts to add ...

 

First, the part of the title that gets replaced with the date is actually two pieces.  The day of the week is separate from the date itself.  SAS already supplies a macro variable with the date:  &sysdate

 

So your title will include

 

title2 "Report Issued on ???? &sysdate";

 

Second, to utilize most functions in macro language, you have to run them through the macro function %SYSFUNC.  So you could be starting with:

 

%let day = %sysfunc(putn("&sysdate"d, weekdate9));

 

There are probably other ways to get there (and this is untested).

 

Finally, when using a date format such as weekdate9, the result is centered.  To get rid of leading and trailing blanks, you could simply add:

 

%let day = &day;

 

Then the title becomes:

 

title2 "Report for &day &sysdate";

Super User
Posts: 5,518

Re: SAS Macro with Title Statement

Posted in reply to Astounding

Good news, now that I had a chance to check my code.  There are two relevant automatic macro variables available.  No calculations are needed, just:

 

title2 "Report for &sysday &sysdate";

 

For extra credit, take a look at &sysdate9 vs. &sysdate.

Super User
Posts: 19,878

Re: SAS Macro with Title Statement

Are those the exact instructions provided? TBH they look incorrect. 

Ask a Question
Discussion stats
  • 3 replies
  • 148 views
  • 1 like
  • 3 in conversation