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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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