Not sure what all of the other loop do loops are for but it looks like you have this metadata on rules.
data rule;
length cre $32 rule $1000;
input cre rule;
cards4;
[IC-A_PoC_ACT] ('[A_PoC_ACT]'n*'AU_BENEFITS_AS_IC'n)/'AU_BENEFITS'n
[IC-A_GoC_ACT] ('[A_PoC_ACT]'n*'AU_BENEFITS_AS_IC'n*'AU_BENEFITS_NZC'n)/'AU_BENEFITS'n
;;;;
Which you could use to create some SAS code like this:
filename code temp;
data _null_;
set rule;
file code;
if _n_>1 then put 'else ' @;
put 'if ' cre=$quote. 'then do;'
/ ' mac="A' _n_ '";'
/ ' value=' rule ';'
/ 'end;'
;
run;
So that you get this code:
if cre="[IC-A_PoC_ACT]" then do;
mac="A1 ";
value=('[A_PoC_ACT]'n*'AU_BENEFITS_AS_IC'n)/'AU_BENEFITS'n ;
end;
else if cre="[IC-A_GoC_ACT]" then do;
mac="A2 ";
value=('[A_PoC_ACT]'n*'AU_BENEFITS_AS_IC'n*'AU_BENEFITS_NZC'n)/'AU_BENEFITS'n ;
end;
Which you could then apply to your data.
options validvarname=any;
data cre_acc ;
length amount 8 cre acc $32 ;
input amount cre acc ;
cards;
10 [IC-A_GoC_ACT] [A_PoC_ACT]
50 [IC-A_GoC_ACT] AU_BENEFITS_AS_IC
20 [IC-A_GoC_ACT] AU_BENEFITS
20 [IC-A_GoC_ACT] AU_BENEFITS_NZC
10 [IC-A_PoC_ACT] [A_PoC_ACT]
20 [IC-A_PoC_ACT] AU_BENEFITS_AS_IC
20 [IC-A_PoC_ACT] AU_BENEFITS
;
proc transpose data=cre_acc out=cre_acc_wide;
by CRE;
id ACC;
var amount;
run;
data want;
set cre_acc_wide;
%include code / source2;
run;
To get the result:
[A_PoC_ AU_BENEFITS_ AU_BENEFITS_ Obs cre _NAME_ ACT] AS_IC AU_BENEFITS NZC mac value 1 [IC-A_GoC_ACT] amount 10 50 20 20 A2 500 2 [IC-A_PoC_ACT] amount 10 20 20 . A1 10
@David_Billa wrote:
Thank you. Do we have any way to accomplish it with arrays too?
I am not sure how array could help with this. You could use ARRAY processing instead of PROC TRANSPOSE to convert your tall input data into wide data that has the variables that the RULE text is referencing.
@David_Billa wrote:
Thank you. Do we have any way to accomplish it with arrays too?
Start here: Using Arrays and decide for yourself where in your process arrays might be helpful.
@Tom Also I would like to understand what is the meaning of $quote. in the code below. How $quote. will resolve during execution?
filename code temp; data _null_; set rule; file code; if _n_>1 then put 'else ' @; put 'if ' cre=$quote. 'then do;' / ' mac="A' _n_ '";' / ' value=' rule ';' / 'end;' ; run;
$QUOTE. is a format. So the value of the CRE variable (which is character) will be printed with quotes around it when it is written to the new code file so that it looks to the SAS processor like a string literal.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.