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

Hello,

 

Could somebody help me to identify the error on this very simple piece of code:

 

data HAVE;

set HAVE;
array columns {*} _numeric_;
SOMA=0;
CONTAGEM=0;

       do i = 1 to dim(columns);

          if abs(columns {i}) >0 then
             CONTAGEM= CONTAGEM+1
             SOMA=SOMA+colunas {i};
          else
            CONTAGEM=CONTAGEM
            SOMA=SOMA;
         end;
     end;

run;

 

The gold is count (and sum) the number of variables of an array that the absolute value (abs) are greater than zero (for example).

 

 

 

 

This code returns this error and I can't interpret it:

 

"

SOMA=SOMA+colunas {i};
____
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,
IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.

38 else
39 CONTAGEM=CONTAGEM
40 SOMA=SOMA;
____
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE,
GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.

41 end;
42 end;
___
161
ERROR 161-185: No matching DO/SELECT statement.

 

 

 

 

Thank you in advance!

 

Krauss

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
data HAVE; /* BAD idea to replace your source data set until you KNOW your
                    code is working correctly*/

set HAVE;
array columns {*} _numeric_;
SOMA=0;
CONTAGEM=0;

       do i = 1 to dim(columns);

          if abs(columns {i}) >0 then DO;
             CONTAGEM= CONTAGEM+1;
             SOMA=SOMA+colunas {i};
end; else do; CONTAGEM=CONTAGEM ; SOMA=SOMA; end; end; run;

EVERY SAS statement needs a ; to end the statement. So when you use

 CONTAGEM= CONTAGEM+1
 SOMA=SOMA+colunas {i};

The first statement Contagem = Contagem +1 is not ended when the compiler encounters SOMA. Since the previous statement involves numeric computation then the compiler expects something related to SOMA in how it is used in the previous computation.

 

Second. If you need multiple statements evaluated as part of an IF /Then /Else then you a DO /END block to tell SAS which multiple statements are conditional.

 

BTW:

          else
            CONTAGEM=CONTAGEM
            SOMA=SOMA;
         end;

is basically a complete waste of electrons. Since you are not changing the values then why bother?

 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

You are missing semi-colons at the end of your commands.

 

In the future, please show us the entire log for your DATA step or PROC, not just the errors, by pasting (as text) the log into the window that appears when you click on the {i} icon. This will preserve the formatting of the log, and allow us to more easily identify where the problem is. Thanks.

--
Paige Miller
Krauss
Fluorite | Level 6
1                                                          The SAS System                           13:15 Tuesday, December 17, 2019

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HtmlBlue
17             STYLESHEET=(URL="file:///C:/Applics/SASHome/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         data work.step1;
27         
28         set work.step1;
29         	array colunas {*} _numeric_;
30          SOMA=0;
31          CONTAGEM=0;
32         
33         do i = 1 to dim(colunas);
34         
35          	if abs(colunas {i}) >0 then
36         		CONTAGEM= CONTAGEM+1
37         		SOMA=SOMA+colunas {i};
             ____
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, 
              IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

38         	else
39         		CONTAGEM=CONTAGEM
40         		SOMA=SOMA;
             ____
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, 
              GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.  

41         	end;
42         end;
           ___
           161
ERROR 161-185: No matching DO/SELECT statement.

43         
2                                                          The SAS System                           13:15 Tuesday, December 17, 2019

44         run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.STEP1 may be incomplete.  When this step was stopped there were 0 observations and 467 variables.
WARNING: Data set WORK.STEP1 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              1605.21k
      OS Memory           27316.00k
      Timestamp           12/18/2019 12:21:47 PM
      Step Count                        45  Switch Count  0
      Page Faults                       2
      Page Reclaims                     215
      Page Swaps                        0
      Voluntary Context Switches        11
      Involuntary Context Switches      0
      Block Input Operations            1024
      Block Output Operations           8
      

45         
46         GOPTIONS NOACCESSIBLE;
47         %LET _CLIENTTASKLABEL=;
48         %LET _CLIENTPROCESSFLOWNAME=;
49         %LET _CLIENTPROJECTPATH=;
50         %LET _CLIENTPROJECTPATHHOST=;
51         %LET _CLIENTPROJECTNAME=;
52         %LET _SASPROGRAMFILE=;
53         %LET _SASPROGRAMFILEHOST=;
54         
55         ;*';*";*/;quit;run;
56         ODS _ALL_ CLOSE;
57         
58         
59         QUIT; RUN;
60         

Where the log indicates the error I have semi-colons already. How should I know where they are missing?

 

Thks!

PaigeMiller
Diamond | Level 26

Each command must end with a semi-colon. Look carefully, there are commands with no semi-colons at the end.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hello @Krauss  did you notice the missing DO and END blocks? I think the following correction is what is required

 


          if abs(columns {i}) >0 then do;
             CONTAGEM= CONTAGEM+1;
             SOMA=SOMA+colunas {i};
			 end;
          else do;
            CONTAGEM=CONTAGEM;
            SOMA=SOMA;
         end;
Krauss
Fluorite | Level 6

I just eliminate the "else part" since it will do it anyway (doing nothing). Problem solved.

 

Thank you for your help.

 

Astounding
PROC Star

Not exactly solved.

 

The sums are wrong whenever there is a negative number.

 

I would suggest paying attention to the suggestion about adding DO and END.

ballardw
Super User
data HAVE; /* BAD idea to replace your source data set until you KNOW your
                    code is working correctly*/

set HAVE;
array columns {*} _numeric_;
SOMA=0;
CONTAGEM=0;

       do i = 1 to dim(columns);

          if abs(columns {i}) >0 then DO;
             CONTAGEM= CONTAGEM+1;
             SOMA=SOMA+colunas {i};
end; else do; CONTAGEM=CONTAGEM ; SOMA=SOMA; end; end; run;

EVERY SAS statement needs a ; to end the statement. So when you use

 CONTAGEM= CONTAGEM+1
 SOMA=SOMA+colunas {i};

The first statement Contagem = Contagem +1 is not ended when the compiler encounters SOMA. Since the previous statement involves numeric computation then the compiler expects something related to SOMA in how it is used in the previous computation.

 

Second. If you need multiple statements evaluated as part of an IF /Then /Else then you a DO /END block to tell SAS which multiple statements are conditional.

 

BTW:

          else
            CONTAGEM=CONTAGEM
            SOMA=SOMA;
         end;

is basically a complete waste of electrons. Since you are not changing the values then why bother?

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 1100 views
  • 1 like
  • 5 in conversation