BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Question
Fluorite | Level 6

Hi,

 

I have created a macro in a column A called " final_macro" in the table attached (Macro_query).

I would like to tell SAS to run it from the column A automatically?

 

Is it possible?

 

Thank you  🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You put CODE into an XSLX file?  Why?

I jumped through the hoops needed to look at your attached file and it appears to CALLS to a macro in each cell.  So not a macro definition at all, just just normal SAS code that happens consist of macro calls.

 

The cleanest way is to write the code to a file and run the file.

So assuming the dataset you get from the spreadsheet is named CALLS and the column with the SAS code is named CALL then use code like this to write that to a file and then use %INCLUDE to run it.

filename code temp;
data _null_;
   set calls;
   file code;
   put call;
run;
%include code / source2;

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

If by "column of table" you mean "a variable in a SAS data set" the answer is without looking in that spread is probably.

A data step can use text in data set, or constructed text, with the CALL Execute statement to submit the text for execution.

However, you are going to have to clarify what you mean by "automatically". Automatically when what happens?

Tom
Super User Tom
Super User

You put CODE into an XSLX file?  Why?

I jumped through the hoops needed to look at your attached file and it appears to CALLS to a macro in each cell.  So not a macro definition at all, just just normal SAS code that happens consist of macro calls.

 

The cleanest way is to write the code to a file and run the file.

So assuming the dataset you get from the spreadsheet is named CALLS and the column with the SAS code is named CALL then use code like this to write that to a file and then use %INCLUDE to run it.

filename code temp;
data _null_;
   set calls;
   file code;
   put call;
run;
%include code / source2;

 

 

Question
Fluorite | Level 6

Thank you Tom, for this.....That gives me what I need exactly, it works  😀

 

Best wishes

 

 

Patrick
Opal | Level 21

I personally would use the approach @Tom proposes because it creates the "cleanest" log. An alternative would be call execute() or the dosubl() function.

%macro test();
  %global i;
  %let i=%eval(&i+1);
  data _null_;
    var=&i;
    put var=;
  run;
%mend;

data macro_calls;
  infile datalines truncover;
  input code $100.;
  datalines4;
%test();
%test();
%test();
%test();
;;;;

data _null_;
  set macro_calls;
  call execute(code);
/*  rc=dosubl(code);*/
run;

 

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
  • 319 views
  • 2 likes
  • 4 in conversation