BookmarkSubscribeRSS Feed
bldudley
Obsidian | Level 7

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!

3 REPLIES 3
Astounding
PROC Star

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";

Astounding
PROC Star

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.

Reeza
Super User

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

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
  • 3 replies
  • 8485 views
  • 1 like
  • 3 in conversation