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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 7879 views
  • 1 like
  • 3 in conversation