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

Hi SAS Forum,

I did a literature survey to understand the difference between “If-then-do-end” vs. %if %then %do %end.

Below conditional logic code (SUGI29 paper 243-29 by Slaughter and Delwiche acknowledged) prints data set called “orders” if the current day is Monday. And creates a table using proc tabulate if the current day is Friday.

%MACRO reports;

%IF &SYSDAY = Monday %THEN %DO;

PROC PRINT DATA = orders NOOBS;

FORMAT OrderDate DATE7.;

TITLE "&SYSDAY Report: Current Orders";

%END;

%ELSE %IF &SYSDAY = Friday %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;

Q: Why cannot we simply replace all the places having %IF %THEN %DO %END and %ELSE %IF %THEN %DO %END with standard IF THEN DO END and ELSE IF THEN DO END ?

Sorry if my question looks like a stupid one.

Miris

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

IF/THEN/DO/etc work inside a data step and or procs.

%IF/%THEN/%DO/%etc work in macro code, for example not in a data step. So they are used to conditionally execute a data step/proc.

View solution in original post

5 REPLIES 5
Reeza
Super User

IF/THEN/DO/etc work inside a data step and or procs.

%IF/%THEN/%DO/%etc work in macro code, for example not in a data step. So they are used to conditionally execute a data step/proc.

jakarman
Barite | Level 11

There are many languages being mixed in your daily SAS usage.

SAS macro language is different from the data-step and that is different to using a proc and there are more.

See: SAS(R) 9.3 Macro Language: Reference how it works.

As being different languages being processed at different moments the interactions can be sometimes a challenge.

It is the programmers task to understand that.

Same intention, different words as Reeza.

---->-- ja karman --<-----
Tom
Super User Tom
Super User

Macro logic is used to conditionally generate code that is then passed onto regular SAS to interpret and execute. In another sense you can think of them as two separate processes.  The different syntax (% versus no %) are what keeps the interpreter (and the programmer) from getting confused.

Cynthia_sas
SAS Super FREQ

Hi:

I explained a lot of these concepts for the beginner in this paper:

http://support.sas.com/resources/papers/proceedings13/120-2013.pdf

cynthia

Mirisage
Obsidian | Level 7

Hi Reeza, Jaap, Tom and Cynthia,

Many thanks to each one of you for this help.

Hi Cynthia,
Your paper is very helpful for me. Thank you very much for it.

Regards

Miris

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 2868 views
  • 9 likes
  • 5 in conversation