Hello I am trying to write this R code in IML is there an help on this
general.d <- function (m, s){
k=length(s)
m1_x = length (m)
sum.s = 0
for (i in 1:k){
sum.s = sum.s+s[i]^2
s_pooled=sqrt(sum.s/k)
}
if (m1_x==1 & k==1){
return (d=m/s)
}
else if (m1_x==2 & k==1){
m_1 = diff(m)
return(d=m_1/s_pooled)
}
else {
m_2 = max(m) - min(m)
return(d_2=m_2/s_pooled)
}
}
general.d <- function (m, s); k=length(s) m1_x = length (m) sum.s = 0 for (i in 1:k); sum.s = sum.s+s[i]^2 s_pooled=sqrt(sum.s/k) if (m1_x==1 & k==1); return (d=m/s); else if (m1_x==2 & k==1){ m_1 = diff(m); return(d=m_1/s_pooled); else { m_2 = max(m) - min(m); return(d_2=m_2/s_pooled); run; quit;
But I get an error code.
What I am doing wrongly I will be glad to receive help
So, we don't really need to see your R code. We do need to see your SAS code and the SAS log which contains the error (saying "But I get an error code" is never enough information).
So, please provide the entire SAS log for your IML (not just the error code) by clicking on the {i} icon (this is mandatory) and pasting your SAS log into the window that appears. Do not provide the SAS log any other way.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 proc iml; NOTE: IML Ready 74 start general_d <- function (m, s); _ 22 200 ERROR 22-322: Syntax error, expecting one of the following: ;, (. ERROR 200-322: The symbol is not recognized and will be ignored. 75 k=length(s); 76 m1_x = length (m); 77 sum_s = 0; 78 for (i in 1:k); ___ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 79 sum_s = sum.s+s[i]^2 _____ _ 22 76 201 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, (, +, -, [, ^, {. ERROR 76-322: Syntax error, statement will be ignored. ERROR 201-322: The option is not recognized and will be ignored. 79 ! sum_s = sum.s+s[i]^2 _ 22 ERROR 22-322: Syntax error, expecting one of the following: ;, #, ##, $, &, (|, *, **, +, -, /, //, :, <, <=, <>, =, >, ><, >=, @, [, ^=, `, |, ||. 80 s_pooled=sqrt(sum.s/k); 81 82 if (m1_x==1 & k==1) _ 22 76 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, +. ERROR 76-322: Syntax error, statement will be ignored. 83 return (d=m/s); 84 85 else if (m1_x==2 & k==1); _ 22 76 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, +. ERROR 76-322: Syntax error, statement will be ignored. 86 m_1 = diff(m); 87 return(d=m_1/s_pooled); 88 89 else 90 m_2 = max(m) - min(m); 91 return(d_2=m_2/s_pooled); 92 run; WARNING: Module GENERAL_D definition is left incomplete. 93 quit; NOTE: Exiting IML. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE IML used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 401.75k OS Memory 28580.00k Timestamp 07/06/2019 07:26:01 PM Step Count 30 Switch Count 0 Page Faults 0 Page Reclaims 134 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 94 95 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 108
Okay, simple question ... there is an interface in PROC IML that allows you to run R code. Are you trying to run your exact R code inside of PROC IML?
Or are you trying to rewrite the R code as native PROC IML code (as your title implies)? You can't simply paste R code into PROC IML and expect it to run. The syntax used by R is completely different than the syntax used by PROC IML.
I am trying to rewrite the R code to Proc IML
Post it at IML forum @Rick_SAS might give you a hand .
> I am trying to write this in IML is there any help on this?
Yes, there are many resources for learning to program in SAS/IML. Start with "10 tips for learning the SAS/IML language."
You can also go straight to the SAS/IML User's Guide.
To add on the resources, there is a eLearning training from SAS, "SAS Programming for R Users" with video presentations, demo codes and exercises. One of the topics is on IML and how to call R from IML. It is free.
Thanks
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 to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.