BookmarkSubscribeRSS Feed
Kleber
Calcite | Level 5

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!

4 REPLIES 4
Reeza
Super User

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;

Reeza
Super User

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;

Kleber
Calcite | Level 5

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

Reeza
Super User

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.

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
  • 2145 views
  • 6 likes
  • 2 in conversation