turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Explanation if statement in arithmetic calculation

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-07-2013 05:10 AM

Please tell me where the following piece of code says not to add 88 if month<>12. I thought it says add 88*multiplied by(dec of each year)

%macro cohort1(mth);

/**DETERMINING FIRST AND LAST MONTH OF PERFORMANCE**/

data _null_;

call symput ("start_mon", &mth+1 + 88*(substr("&mth.",5,2) = 12));

call symput ("end_mon", &mth+100 );

run;

%put &start_mon &end_mon;

%mend;

%cohort1(200512);Explanation if statement in arithmetic calculation

Accepted Solutions

Solution

08-07-2013
05:18 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to M_ishk_a

08-07-2013 05:18 AM

Explanation is as follows:

The line of code

call symput ("start_mon", &mth+1 + 88*(substr("&mth.",5,2) = "12"));

is saying the following

if (substr("&mth.",5,2) = "12") then call symput ("another_start_mon", &mth + 1 + 88);

else call symput ("another_start_mon", &mth+1);

how the shorten line of codes works as follows:

SAS evaluates quantities inside parentheses before performing any operations.

Let’s call the macro with the following value %cohort1(200512).

SAS will first evaluate the parentheses (substr("&mth.",5,2) = "12")) in this case &mth is 12 so the value inside the parameter would be true or 1.

So the expression is actually &mth+1 + 88*(1).

&mth will the evaluate &mth plus 1 plus (88 * 1)

Let’s call the macro with the following value %cohort1(200601) in this case &mth is not 12 so the value inside the parameter would be false or 0.

So the expression is actually &mth+1 + 88*(0).

&mth will the evaluate &mth plus 1 plus (88 * 0)

Fruther reading: http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm#a0007... see Numeric Comparisons

All Replies

Solution

08-07-2013
05:18 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to M_ishk_a

08-07-2013 05:18 AM

Explanation is as follows:

The line of code

call symput ("start_mon", &mth+1 + 88*(substr("&mth.",5,2) = "12"));

is saying the following

if (substr("&mth.",5,2) = "12") then call symput ("another_start_mon", &mth + 1 + 88);

else call symput ("another_start_mon", &mth+1);

how the shorten line of codes works as follows:

SAS evaluates quantities inside parentheses before performing any operations.

Let’s call the macro with the following value %cohort1(200512).

SAS will first evaluate the parentheses (substr("&mth.",5,2) = "12")) in this case &mth is 12 so the value inside the parameter would be true or 1.

So the expression is actually &mth+1 + 88*(1).

&mth will the evaluate &mth plus 1 plus (88 * 1)

Let’s call the macro with the following value %cohort1(200601) in this case &mth is not 12 so the value inside the parameter would be false or 0.

So the expression is actually &mth+1 + 88*(0).

&mth will the evaluate &mth plus 1 plus (88 * 0)

Fruther reading: http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm#a0007... see Numeric Comparisons