Hello everyone,
I wonder may I ask the SAS macro question in terms of "%sysday" as I tested those options in SAS,
and except for the first one generating error, the other three seemed worked!
Thank you very much for reading and any advice.
%macro execute; [ insert_statement_here_] proc print data=sashelp.heart; run; %end; %mend execute; %execute
The question is:
Which statement completes the program so that the PROC PRINT step executes on Thursday?
A.
if &sysday = Thursday then %do.
B.
%if &sysday =Thursday %then %do.
C.
%if "&sysday"= Thursday %then %do.
D.
%if &sysday = "Thursday" %then %do.
I do not really understand the differences among B,C, and D
Thank you!!
Test it. My system is showing sys day as Monday, so I'm using Monday in my tests.
*check for trailing spaces, look where 000 ends up; %put &sysday.000; *check for quotes on both sides; %if "&sysday."="Monday" %then %do; %put ERROR- Quotes on both sides; %end; *check for quotes on no sides; %if &sysday=Monday %then %do; %put ERROR- No Quotes on either side; %end;
Output:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 *check for trailing spaces, look where 000 ends up; 70 %put &sysday.000; Monday000 71 72 *check for quotes on both sides; 73 %if "&sysday."="Monday" %then %do; 74 %put ERROR- Quotes on both sides; Quotes on both sides 75 %end; 76 77 *check for quotes on no sides; 78 %if &sysday=Monday %then %do; 79 %put ERROR- No Quotes on either side; No Quotes on either side 80 %end; 81 82 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 93
Note that in SAS 9.4 TS1M5+ you can run %IF/%THEN in open code and do not need to wrap it a macro.
@jc3992 wrote:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 options mprint; 74 75 %macro execute; 76 %if "&sysday" = "Thursday" %then %do; 77 proc print data=sashelp.heart; 78 run; 79 %end; 80 81 %mend execute; 82 %execute; 83 84 85 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 98So if I add quote to the &sysday, I have to add the quote to the other side, like the above?
The log showed no error either.
Look at the quotation marks and & vs %, they're in different places.
I don't see the answer I'd expect but I'm guessing that A and B don't match what's in the book. Can you please confirm A & B are posted correctly?
@jc3992 wrote:
Hello everyone,
I wonder may I ask the SAS macro question in terms of "%sysday" as I tested those options in SAS,
and except for the first one generating error, the other three seemed worked!
Thank you very much for reading and any advice.
%macro execute; [ insert_statement_here_] proc print data=sashelp.heart; run; %end; %mend execute; %executeThe question is:
Which statement completes the program so that the PROC PRINT step executes on Thursday?
A.
if %sysday = Thursday then %do.
B.
%if %sysday =Thursday %then %do.
C.
%if "&sysday"= Thursday %then %do.
D.
%if &sysday = "Thursday" %then %do.
I do not really understand the differences among B,C, and D
Thank you!!
1. It's &sysday, not %sysday.
2. I do not really understand the differences among B,C, and D
Then you are not looking carefully. Look at the quotes
3. the other three seemed worked!
I doubt C and D work.
Pay attention, these are not details.
@jc3992 wrote:
Hello everyone,
I wonder may I ask the SAS macro question in terms of "%sysday" as I tested those options in SAS,
and except for the first one generating error, the other three seemed worked!
Thank you very much for reading and any advice.
%macro execute; [ insert_statement_here_] proc print data=sashelp.heart; run; %end; %mend execute; %executeThe question is:
Which statement completes the program so that the PROC PRINT step executes on Thursday?
A.
if %sysday = Thursday then %do.
B.
%if %sysday =Thursday %then %do.
C.
%if "&sysday"= Thursday %then %do.
D.
%if &sysday = "Thursday" %then %do.
I do not really understand the differences among B,C, and D
Thank you!!
Actually since I would expect a semicolon after %do they are likely all wrong. Changing Thursday to Tuesday, since that is the day I tested this:
621 %macro execute; 622 %if %sysday =Tuesday %then %do. 623 proc print data=sashelp.heart; 624 run; 625 %end; ERROR: There is no matching %DO statement for the %END. This statement will be ignored. 626 627 %mend execute; NOTE: The macro EXECUTE completed compilation with errors.
Since none of the choices end in a semicolon all will generate the same no matching %do for the %end.
Spelling and punctuation do count in programming.
Sorry I got a typo for the (A) and (B).
I have changed them to "&sysday".
I just do not really understand when we should add a quote?
Thank you!!
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 options mprint; 74 75 %macro execute; 76 %if "&sysday" = "Thursday" %then %do; 77 proc print data=sashelp.heart; 78 run; 79 %end; 80 81 %mend execute; 82 %execute; 83 84 85 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 98
So if I add quote to the &sysday, I have to add the quote to the other side, like the above?
The log showed no error either.
Test it. My system is showing sys day as Monday, so I'm using Monday in my tests.
*check for trailing spaces, look where 000 ends up; %put &sysday.000; *check for quotes on both sides; %if "&sysday."="Monday" %then %do; %put ERROR- Quotes on both sides; %end; *check for quotes on no sides; %if &sysday=Monday %then %do; %put ERROR- No Quotes on either side; %end;
Output:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 *check for trailing spaces, look where 000 ends up; 70 %put &sysday.000; Monday000 71 72 *check for quotes on both sides; 73 %if "&sysday."="Monday" %then %do; 74 %put ERROR- Quotes on both sides; Quotes on both sides 75 %end; 76 77 *check for quotes on no sides; 78 %if &sysday=Monday %then %do; 79 %put ERROR- No Quotes on either side; No Quotes on either side 80 %end; 81 82 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 93
Note that in SAS 9.4 TS1M5+ you can run %IF/%THEN in open code and do not need to wrap it a macro.
@jc3992 wrote:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 options mprint; 74 75 %macro execute; 76 %if "&sysday" = "Thursday" %then %do; 77 proc print data=sashelp.heart; 78 run; 79 %end; 80 81 %mend execute; 82 %execute; 83 84 85 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 98So if I add quote to the &sysday, I have to add the quote to the other side, like the above?
The log showed no error either.
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.