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:
This is what I have so far as my output:
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!
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";
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.
Are those the exact instructions provided? TBH they look incorrect.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.