Solved
Contributor
Posts: 36

# Reduce redundant code

Hi All,

Please help, I want to perform the same function for 3 different data sets. Is there a way to do this without having to create 3 separate data sets? Can I use a macro?

Eg:

data a;

set sum1;

dd=datepart(day);

month=month(dd);

year=year(dd);

month=month(dd);

if day(dd) le &max_daya. then day_group="&max_daya.";

if class le 97 then group='c' ;

if class gt 97 and class le 99 then group='02b';

if class in (97,98,99) then group='A';

if class ge 100 then group='H';

cost=cost/100;

vatexcl=cost/1.14;

format dd date.;

run;

data b;

set sum2;

dd=datepart(day);

month=month(dd);

year=year(dd);

month=month(dd);

if day(dd) le &max_dayb. then day_group="&max_daya.";

if class le 97 then group='c' ;

if class gt 97 and class le 99 then group='02b';

if class in (97,98,99) then group='A';

if class ge 100 then group='H'';

cost=cost/100;

vatexcl=cost/1.14;

format dd date.;

run;

data c;

set sum3;

dd=datepart(day);

month=month(dd);

year=year(dd);

month=month(dd);

if day(dd) le &max_dayc. then day_group="&max_daya.";

if class le 97 then group='c' ;

if class gt 97 and class le 99 then group='02b';

if class in (97,98,99) then group='A';

if class ge 100 then group='H';

cost=cost/100;

vatexcl=cost/1.14;

format dd date.;

run;

Accepted Solutions
Solution
‎06-06-2012 05:46 AM
Super Contributor
Posts: 350

## Re: Reduce redundant code

Hi,

Yes you can do that..

%macro Test(output,input);

data &output;

set &input;

dd=datepart(day);

month=month(dd);

year=year(dd);

month=month(dd);

if day(dd) le &max_daya. then day_group="&max_daya.";

if class le 97 then group='c' ;

if class gt 97 and class le 99 then group='02b';

if class in (97,98,99) then group='A';

if class ge 100 then group='H';

cost=cost/100;

vatexcl=cost/1.14;

format dd date.;

run;

%mend test;

%test(a,sum1);

%test(b,Sum2);

%test(c,Sum3);

Thanks,

Shiva

All Replies
Solution
‎06-06-2012 05:46 AM
Super Contributor
Posts: 350

## Re: Reduce redundant code

Hi,

Yes you can do that..

%macro Test(output,input);

data &output;

set &input;

dd=datepart(day);

month=month(dd);

year=year(dd);

month=month(dd);

if day(dd) le &max_daya. then day_group="&max_daya.";

if class le 97 then group='c' ;

if class gt 97 and class le 99 then group='02b';

if class in (97,98,99) then group='A';

if class ge 100 then group='H';

cost=cost/100;

vatexcl=cost/1.14;

format dd date.;

run;

%mend test;

%test(a,sum1);

%test(b,Sum2);

%test(c,Sum3);

Thanks,

Shiva

Contributor
Posts: 36

Thank you Shivas

Posts: 3,852

## Re: Reduce redundant code

if day(dd) le &max_daya. then day_group="&max_daya.";

if day(dd) le &max_dayb. then day_group="&max_dayb.";

if day(dd) le &max_dayc. then day_group="&max_dayc.";

Perhaps

if day(dd) le &&max_day&output. then day_group="&&max_day&output.";

Where are those variables?

Contributor
Posts: 36

## Re: Reduce redundant code

Hi Shivas

I could really use your help. Please advise on the below.

I want to automate programs by adding them to my crontab to run daily.
Instead of adding in several entries for the different programs to my crontab, how do I create a macro/program that has all the program calls in it(the different program names)
Also before running the program each day I want the macro to check if the previous days data ran successfully and if the log dependancy for today is met before kicking of the jobs.

Eg: Prog02may2012.sas can only run if the Prog01may2012.sas ran successfully. Also the dependancy "extract.log.ok" needs to be met before I run any programs.

Hope this makes sense.
Thanks, appreciate it.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 237 views
• 0 likes
• 3 in conversation