BookmarkSubscribeRSS Feed
Lawongd
Calcite | Level 5

 

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

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Lawongd
Calcite | Level 5
 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        
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Lawongd
Calcite | Level 5

I am trying to rewrite the R code to Proc IML

Ksharp
Super User

Post it at IML forum @Rick_SAS  might give you a hand .

Rick_SAS
SAS Super FREQ

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

 

arthurcavila
Obsidian | Level 7

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.

Lawongd
Calcite | Level 5

Thanks

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 8 replies
  • 1735 views
  • 0 likes
  • 5 in conversation