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

Hello

What is the way to create code that run macro based on 2 arguments from data set?

The question is actually how to create this code austomatically?(In real word the data set includes many rows so I am looking for a way to run the macro from these values automatically)

%RRR(VAR=Wealth ,Format=F1MT )
%RRR(VAR=obligo ,Format=F2MT )
%RRR(VAR=LoansBal ,Format=F3Mt )

 

 

%macro RRR(VAR,Format);
proc sql;
create table a_dist_continuous as
select  Left("&VAR.") as Var_name  LENGTH=300,
       put(&VAR.,&Format.) as Cat LENGTH=100,
        count(*) as nr&mon.,
		calculated nr&mon./(select count(*) as total_nr from ttt) as tamhil&mon. format=percent8.2
from ttt
group by  calculated CAT
;
quit;
%mend RRR;

Data MAcro_need_to_run;
infile datalines dsd;
input field $ Fmt $;
cards;
Wealth,F1MT
obligo,F2MT
LoansBal,F3Mt
;
Run;



proc format;
value F1MT
.='(b1) NULL'
0='(b2) 0'
0<-1000='(b3) 0-1K'
1000<-5000='(b4) 1-5K'
5000<-High='(b5) 5K+'
Low-<0='(b6) Neg'
other='(b7) other'
;
Run;

proc format;
value F2MT
0-100='(b1) POS 0-100'
100<-High='(b2) POS 100+'
Low- -100='(b3) Neg_100+'
-100 - 0='(b4) Neg_0-100'
other='(b5) other'
;
Run;


proc  format;
value F3Mt
Low-0,.='(a1) 0/Null/Neg'
0<-High='(a2) Pos'
;
Run;


%RRR(VAR=Wealth  ,Format=F1MT )
%RRR(VAR=obligo  ,Format=F2MT )
%RRR(VAR=LoansBal  ,Format=F3Mt )


 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Data MAcro_need_to_run;
infile datalines dsd;
input field $ Fmt $;
cards;
Wealth,F1MT
obligo,F2MT
LoansBal,F3Mt
;
Run;
data _null_;
set MAcro_need_to_run;
call execute(catt('%RRR(Var=',field,',Format=',fmt,')'));
run;

View solution in original post

2 REPLIES 2
Ksharp
Super User
Data MAcro_need_to_run;
infile datalines dsd;
input field $ Fmt $;
cards;
Wealth,F1MT
obligo,F2MT
LoansBal,F3Mt
;
Run;
data _null_;
set MAcro_need_to_run;
call execute(catt('%RRR(Var=',field,',Format=',fmt,')'));
run;
Tom
Super User Tom
Super User

To prevent the macro from executing while call execute is trying to stack up the code to run later make sure to add %nrstr() macro quoting.

call execute(catt('%nrstr(%RRR)(Var=',field,',Format=',fmt,')'));

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 307 views
  • 4 likes
  • 3 in conversation