BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jc3992
Pyrite | Level 9

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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


 

View solution in original post

7 REPLIES 7
Reeza
Super User

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;
%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!!


 

ChrisNZ
Tourmaline | Level 20

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.

 

ballardw
Super User

@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;
%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!!


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.

jc3992
Pyrite | Level 9

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!!

Reeza
Super User
Similar to basic math - both sides of the equal sign need to match. If you have quotes on one side you need them on the other.
jc3992
Pyrite | Level 9
 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. 

Reeza
Super User

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


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 1551 views
  • 0 likes
  • 4 in conversation