Your SAS programs, embedded in web apps and elsewhere

Another question about can you jump from one position to another in a store

Reply
N/A
Posts: 0

Another question about can you jump from one position to another in a store

I have received an answer about how to jump from one place to another place in the data step of a stored process; however....can you jump from a step inside a data step to a totally differenct location, outside of that same data step?

Say you had the following pseudocode:

stpbegin;
Data Start;
If answer = maybe then do;
Link outtahere;
end;
run;

Proc Sql;
Sequel code goes here;
run;
quit;

Data Nextstep;
outtahere:
The spot I want to jump to from a previous data step;
Can this be done?

stpend;


The reason I'm asking is that I am trying to incorporate options for different kinds of reports and sorts into a stored process. I will have some parameters that let me pick a report of employees,or where employees work, or what their positions are; on top of that, I have other parameters that allow observations to be sorted by employee, or by location, or by job and so forth.

So.... If I pick one bunch of parameter, I want my code to jump to a particular sorting and reporting bunch of code, however, if I pick a bunch of other parameters, I then want to go to the code for those parameters.

Any ideas out there? Thanks in advance!!
SAS Super FREQ
Posts: 8,861

Re: Another question about can you jump from one position to another in a store

Posted in reply to deleted_user
Hi!
The way you conditionally execute entire steps or partial sections of code is by using SAS Macro programming conditional logic.

In this previous post,
http://support.sas.com/forums/thread.jspa?messageID=5944᜸
the code showed running a weekly report vs running a daily report using Macro conditional logic. That example is relevant to your question.

The SAS Macro facility is like a big typewriter. You can do something as simple as this:
[pre]
** generate 1 PROC PRINT depending on the value of macro var;
proc print data=sashelp.class;
%if %upcase(&macvar) = ONE %then %do;
Title 'One Title';
var name age height;
%end;
%else %if %upcase(&macvar) = TWO %then %do;
Title 'Other Title';
var name sex age height weight;
%end;
run;
[/pre]

What is inside the %IF could be a piece of one step, or could be a WHOLE step:

[pre]
** generate an entire section of code or a different section of code;
%if %upcase(&macvar) = ONE %then %do;
proc print data=sashelp.class;
Title 'Whole PROC PRINT Step';
var name age height;
run;
%end;
%else %if %upcase(&macvar) = TWO %then %do;
proc sql;
create table wombat as
select * from sashelp.class
where age gt 13;
quit;

proc print data=wombat;
title 'Other Condition';
run;
%end;

[/pre]

The only limitation is that conditional macro logic must be contained within a SAS Macro program (a piece of code that you define with a
%MACRO/%MEND section).

So, as a stored process, the code would look something like this:
[pre]
%global macvar;

%macro ckparms;
%if %upcase(&macvar) = ONE %then %do;
proc print data=sashelp.class;
Title 'Whole PROC PRINT Step';
var name age height;
run;
%end;
%else %if %upcase(&macvar) = TWO %then %do;
proc sql;
create table wombat as
select * from sashelp.class
where age gt 13;
quit;

proc print data=wombat;
title 'Other Condition';
run;
%end;

proc freq data=sashelp.shoes;
tables region;
title 'PROC FREQ will run for BOTH values of &MACVAR';
title2 "Current value of MACVAR= &macvar";
run;
%mend ckparms;

%stpbegin;
%ckparms;
%stpend;
[/pre]

For more help with Macro programming examples, I recommend the SAS Macro facility documentation. Your best bet to use the SAS Macro facility within a stored process is to:
1) start with a working SAS program that produces both the outputs (or all the outputs) you want;
2) modify the program in #1 to use hard-coded %LET statements and make sure that you have the right set of macro variables to generate all your alternate outputs;
3) put the program from #2 into a SAS Macro program and include conditional logic -- test your program with all the possible values of the macro variables that your users will be able to send. Make sure that all outputs are the correct output. At this point, using SYMBOLGEN, MPRINT and MLOGIC options will help you debug your macro program logic.
4) FINALLY, turn the program from #3 into a stored process. Up until this step, you have NOT been running code as a stored process. You are doing all your development for #1, #2 and #3 in an EG code node or in SAS Display Manager.

For help with specific macro programming tasks, your best bet is to contact SAS Technical Support.

cynthia
N/A
Posts: 0

Re: Another question about can you jump from one position to another in a store

Posted in reply to Cynthia_sas
And thank you, Cynthia..... I had started coding that concept yesterday afternoon, based on what I was gleaning from a book titled, "SAS Macro programming made easy." Your reply was much shorter and more to the point.

I appreciate your help very much.
Ask a Question
Discussion stats
  • 2 replies
  • 191 views
  • 0 likes
  • 2 in conversation