hi all,
The dataset orders gets created ,nothing's wrong my infile but my micro code not working.Anyone knows why,please?
PS.at least for sysday=wed should work but it doesnot. And in additon to this can i use the second code below for the same purpose.Will it work.Can i use automatic macro variables within a sas code?
options mprint;
DATA orders;
INFILE 'C:\Users\Trajce\Contacts\Desktop\Orders.txt';
INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity;
RUN;
%MACRO reports;
%IF &SYSDAY = Monday %THEN %DO;
PROC PRINT DATA = orders NOOBS;
FORMAT OrderDate DATE7.;
TITLE "&SYSDAY Report: Current Orders";
%END;
%ELSE %IF &SYSDAY = WEDNESDAY %THEN %DO;
PROC TABULATE DATA = orders;
CLASS CustomerID;
VAR Quantity;
TABLE CustomerID ALL, Quantity;
TITLE "&SYSDAY Report: Summary of Orders";
%END;
%MEND reports;
RUN;
%reports
RUN;
second code:
DATA orders;
INFILE 'C:\Users\Trajce\Contacts\Desktop\Orders.txt';
INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity;
IF &SYSDAY = Monday THEN DO;
PROC PRINT DATA = orders NOOBS;
FORMAT OrderDate DATE7.;
TITLE "&SYSDAY Report: Current Orders";
END;
ELSE IF &SYSDAY = WEDNESDAY THEN DO;
PROC TABULATE DATA = orders;
CLASS CustomerID;
VAR Quantity;
TABLE CustomerID ALL, Quantity;
TITLE "&SYSDAY Report: Summary of Orders";
END;
RUN;
Are you running in EG or Base?
What does the log say when you run that line of code.
%put &sysday;
SAS is case sensitive.
It should be Wednesday not WEDNESDAY.
it was actually Wednesday and then changed to WEDNESDAY.Did not work in either way
output &sysday and see what it says then.
Sorry Reeza.Dont know what you mean.
@Ballard
"If you aren't closing and restarting SAS daily then you would have unexpected values.Second is to insure the proper case when comparing using equal signs"
Is it recommended that i restart my SAS daily for Macros in order to work?
Are you running in EG or Base?
What does the log say when you run that line of code.
%put &sysday;
it is BASE and %put &sysday is giving me Thursday....Weird but thank you guys a lot
It's reporting the date information from the computer system clock from when the SAS session started. If you're system date isn't Thursday but you started SAS and didn't shut it down since last week you could get Thursday. Try %put &sysdate as well. If the date isn't today you have another clue.
ok my SAS just resolved sysday to be Thursday and when i changed to sysday=thursday i did get results.
could this something to do with my PC settings ?
One issue could be that SYSDAY has the value the SAS session started. If you aren't closing and restarting SAS daily then you would have unexpected values.Second is to insure the proper case when comparing using equal signs. When I resolved SYSDAY on my system the result was Wednesday" not the WEDNESDAY used in your code. You may want to use %upcase(&sysday)=WEDNESDAY or use the case matching SYSDAY.
hi,
Can any one show me why Monday does not need to be in quote as
%IF &SYSDAY = "Monday" %THEN %DO;
?
Thanks
In the MACRO processor everything is strings. So if you are comparing a value quotes are not required, unless the value you want needs them.
This is one reason for using "¯ovariable" in data steps instead of having the macro variable include quotes.
can you please illustrate with examples? My understanding is that macro variables are always in quotes when used in the TITLE, FOOTNOTE statements. But when they are quoted in other statements, it becomes confusing. Thanks
In a title or other places you would use a text literal:
%let val = Idaho;
Title " Report for &val"; which resolve to Title " Report for Idaho"; from the macro processor.
If you devine val as "Idaho" then one of two things are likely happen:
If you use
title 'Report for &val'; you don't resolve the macro variable because it is within single quotes.
If you use
title "Report for &val"; then the macro processor produces: Title "Report for "Idaho" "; and Idaho is OUTSIDE the quoted string required for title and isn't one of the acceptable options for title and will generate an error. There are ways to use the "value" definition but they get to be a lot of work, especially if you ever want to combine more than one macro variable in a statement.
In a data step:
data want;
set have;
if state = "&val" then do; other code.
In this example you original approach would work. But This way you can tell immediately in the code that we are expecting a text literal (and you enhanced program editor will help with that).
But suppose I want the macro variable to reference a variable name:
%let var = Total_Sales;
Data want;
set have;
Someothervariable = &var * 1.05;
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.