Call execute to work with another program.sas

Reply
New Contributor
Posts: 2

Call execute to work with another program.sas

Hello,

I know that write "call execute" to work with two programs sas (for example) is no the useful way but, i'd like to work using it for this...

I've the following (example) situation:

Data test1;

Input name $ sector $;

Datalines;

John Sales

Bryan Comercial

Tedd Sales

;

Run;

Data test2;

Set test1;

Call execute (

‘ %let var1 = “something1”;

  %let var2 = “something2”;

  %let var3 = “something3”; (in this 3 vars, I work with fixed values.... but I need (and you'll see below, work with var1, var2 ou 3.... receive a value stored in a variable (colunm) for example... Sector colunm..)

  %let var4 = "%include and type the way where another program .sas was save”;

Run;

In this case my program is running without problems but, I need this program receive the value of some variable (column) and pass this value within the command. The idea would be something like this....


Data test2;

Set test1;

Receive here the value, for example -> new_var = variable (column) sector

Call execute (

‘ %let var1 = new_var (that I create above...)

  %let var2 = “something2”;

  %let var3 = “something3”;

  %let var4 = "%include and type the way where another program .sas was save”;

Run;

Please, can you help me with this?

Thanks!

Super User
Posts: 19,877

Re: Call execute to work with another program.sas

I don't see how test1 comes into play.

It looks like you want to create a macro that takes specific parameters and then use call execute to call the macro?

call symput/call symputx is also used to create macro variables from variables in a dataset.

If you could elaborate someone can provide sample code, but also here's an example of a macro with a parameter from a dataset:

data sample;
do date='01Jan2014'd to '31Jan2014'd;
  output;
end;
run;

%macro print_date(date);

proc print data=sample;
where date="&date"d;
format date date9.;
run;

%mend;

%let date_start=05Jan2014;
%let date_end=11Jan2014;

data _null_;
  do date1="&date_start"d to "&date_end"d by 1;
  str='%print_date('||put(date1, date9.)||');';
  call execute(str); 
  end;
run;

Super User
Posts: 19,877

Re: Call execute to work with another program.sas

And creating a macro variable from dataset:

data want;

set sashelp.class;

call symput('name'||put(_n_,2.), name);

run;

data want;

set sashelp.class;

call symput('name'||put(_n_,2. -l), name);

run;

%put &name1;

%put &name10;

New Contributor
Posts: 2

Re: Call execute to work with another program.sas

Good evening Reeza,

Thanks for your colaboration!

I thought in replacing macros for several sas programs because I have 132 bases, they'll create using joins between other bases. Are 132 bases and 132 different businesses rules. I tried to use the programs because I thought the project could be more organized than many macros in a single program. I thought in the project this way because there is no escape from need to create 132 rules of different joins ... unfortunately...

Super User
Posts: 19,877

Re: Call execute to work with another program.sas

Fair enough. If the joins are a lookup, perhaps proc format could help?

Regardless, using call symput is probably your best bet to creating the macro variables and then call execute to include your code.

Ask a Question
Discussion stats
  • 4 replies
  • 512 views
  • 6 likes
  • 2 in conversation