Your SAS programs, embedded in web apps and elsewhere

SAS Macros to Run Different Datasets

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

SAS Macros to Run Different Datasets

Hi all,

I am trying to create a Web Stored Process that uses a single sourcefile to create different reports.

I would imagine I'd need different Macros for each datastep, like below.

 

libname sourcefile 'SingleSourceFile';

run;

 

data &one;

set sourcefile;

where b=1;

run;

 

data &two;

set sourcefile;

where b=2;

run;

 

data &three;

set sourcefile;

where b=3;

run;

 

 

The Stored Process will ask user to select report to run and point and run a datastep based on what the Macro Varible.

 

If possible, can someone point me to any resouce that I can use to create this solution.

 

Thanks for your help all.

 

Ruzvmun

 

 

 

 


Accepted Solutions
Solution
4 weeks ago
Regular Contributor
Posts: 158

Re: SAS Macros to Run Different Datasets

You might want to use a macro statement that checks what the user want and then select which report to create?!

 

 

Lets say you have a prompt called reportSelection and it contains two reports -R1 and R2.

 

As an example STP code could look something like:

 

%macro select_report();

  %if &reportSelection = R1 %then %do;

    data out;

       set sourcefile;

       where b = 1;

    run;

 

    proc tabulate data=out;

       ......

      .....

   run;

 

  %end;

 

  %if &reportSelection = R2 %then %do;

    data out;

       set sourcefile;

       where b = 2;

    run;

   proc print data=out;

   run;

  %end;

 

 

 

%mend;

%select_report;

 

Two different data selections and different outputs Smiley Happy

 

//fredrik

View solution in original post


All Replies
Super User
Super User
Posts: 6,718

Re: SAS Macros to Run Different Datasets

I don't understand the question. If you want a single program to generate multiple reports why not just code the program to generate multiple reports?

Are you asking how to make the program conditionally generate only some of the reports based on the user's choice?

New Contributor
Posts: 4

Re: SAS Macros to Run Different Datasets

Hi Tom,

Yes...based on prompt user selects, run specific data step and leave out the rest. Does that make sense.

I apologize for the confustion, still a SAS novice.

Solution
4 weeks ago
Regular Contributor
Posts: 158

Re: SAS Macros to Run Different Datasets

You might want to use a macro statement that checks what the user want and then select which report to create?!

 

 

Lets say you have a prompt called reportSelection and it contains two reports -R1 and R2.

 

As an example STP code could look something like:

 

%macro select_report();

  %if &reportSelection = R1 %then %do;

    data out;

       set sourcefile;

       where b = 1;

    run;

 

    proc tabulate data=out;

       ......

      .....

   run;

 

  %end;

 

  %if &reportSelection = R2 %then %do;

    data out;

       set sourcefile;

       where b = 2;

    run;

   proc print data=out;

   run;

  %end;

 

 

 

%mend;

%select_report;

 

Two different data selections and different outputs Smiley Happy

 

//fredrik

New Contributor
Posts: 4

Re: SAS Macros to Run Different Datasets

Thank you Fred,

this worked and now I Boss is happySmiley Happy

☑ This topic is solved.

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

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