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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
shivas
Pyrite | Level 9

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

View solution in original post

4 REPLIES 4
shivas
Pyrite | Level 9

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

Havi
Obsidian | Level 7

Thank you ShivasSmiley Happy

data_null__
Jade | Level 19

What about....

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?

Havi
Obsidian | Level 7

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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