BookmarkSubscribeRSS Feed
Fadams12
Calcite | Level 5

Hello, I'm trying to run this code, and I am getting an error message, what do I need to do to in line 38 to get this to get it to work?  

 

Data temp (drop=z);
set work.complete22;
array DXS[18] $ dx1-dx18;
CO_FLAG = 0;
 
do z= 1 to 18;
 
if substr(DXS {z},1,5) IN:('T5801' 'T5804' 'T5811' 'T5814' 'T5891' 'T5894' 'T5802’ ‘T5803’ ‘T5812’ ‘T5813’)
 
            or substr(DXS {z},1,6)IN:(‘T582X2’ ‘T582X3’ ‘T588X3’ ‘T5892' 'T582X1' 'T582X4' 'T588X1' 'T588X4')
 
                                 or DXS{z} in: (‘T5882X2’)
 
            then CO_FLAG = 1;
 
            leave;
 
            END;
 
            run;
 
            or substr(DXS {z},1,6)IN:(‘T582X2’ ‘T582X3’ ‘T588X3’ ‘T5892' 'T582X1' 'T582X4'
36 ! 'T588X1' 'T588X4')
37
38                                    or DXS{z} in: (‘T5882X2’)
                                                     -
                                                     22
                                                     76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
              a datetime constant, a missing value, iterator, (.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
46 REPLIES 46
ballardw
Super User

Please provide the entire procedure or data step log. Sometimes the place that SAS shows the error is because of something missing on a line much earlier. Also, please copy the text from the LOG, on the forum open a text window using the </> icon that appears above the message window and paste the text there. The forum software reformats text pasted into the main message window and may introduce or remove characters, usually not visible, that were not in your log.

Fadams12
Calcite | Level 5
Data temp (drop=z);
5    set work.complete22;
6    /* recoding age */
7    if AGE_KEY >=0 and AGE_KEY <= 4 then agegroup=1;
8    if  AGE_KEY >=5  and AGE_KEY <= 9 then agegroup=2;
9    if  AGE_KEY >=10 and AGE_KEY <= 14 then agegroup=3;
10   if  AGE_KEY >=15  and AGE_KEY <= 19 then agegroup=4;
11   if  AGE_KEY >=20  and AGE_KEY <= 24 then agegroup=5;
12   if  AGE_KEY >=25  and AGE_KEY <=29 then agegroup=6;
13   if  AGE_KEY >=30  and AGE_KEY <= 34 then agegroup=7;
14   if  AGE_KEY >=35  and AGE_KEY <= 39 then agegroup=8;
15   if  AGE_KEY >=40  and AGE_KEY <= 44 then agegroup=9;
16   if  AGE_KEY >=45  and AGE_KEY <= 49 then agegroup=10;
17   if  AGE_KEY >=50  and AGE_KEY <= 54 then agegroup=11;
18   if  AGE_KEY >=55  and AGE_KEY <= 59 then agegroup=12;
19   if  AGE_KEY >=60  and AGE_KEY <= 64 then agegroup=13;
20   if  AGE_KEY >=65  and AGE_KEY <= 69 then agegroup=14;
21   if  AGE_KEY >=70  and AGE_KEY <= 74 then agegroup=15;
22   if  AGE_KEY >=75  and AGE_KEY <= 79 then agegroup=16;
23   if  AGE_KEY >=80  and AGE_KEY <= 84 then agegroup=17;
24   if  AGE_KEY >=85 then agegroup=18;
25   else if AGE_KEY =. then agegroup =19;
26
27   /*    *primary dx only;*/
28
29   array DXS[18] $ dx1-dx18;
30   CO_FLAG = 0;
31
32   do z= 1 to 18;
33
34   if substr(DXS {z},1,5) IN:('T5801' 'T5804' 'T5811' 'T5814' 'T5891' 'T5894' 'T5802’ ‘T5803’
34 ! ‘T5812’ ‘T5813’)
35
36               or substr(DXS {z},1,6)IN:(‘T582X2’ ‘T582X3’ ‘T588X3’ ‘T5892' 'T582X1' 'T582X4'
36 ! 'T588X1' 'T588X4')
37
38                                    or DXS{z} in: (‘T5882X2’)
                                                     -
                                                     22
                                                     76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
              a datetime constant, a missing value, iterator, (.
 
ERROR 76-322: Syntax error, statement will be ignored.
Tom
Super User Tom
Super User

I think the code looks ok up to the point you stopped.  After that should be either an semicolon to define a subsetting if statement (probably not something you would do in the middle of a DO loop) or the THEN keyword to continue defining the IF statement.

 

Otherwise you might have introduced some invisible character, or perhaps one of those quotes is not actually a quote but is instead a typesetting "stupid" quote.

fadamso12
Calcite | Level 5
1    data complete22;
2    set "C:\Users\hjt09632\Desktop\complete22.sas7bdat";
3    run;

NOTE: There were 750108 observations read from the data set
      C:\Users\hjt09632\Desktop\complete22.sas7bdat.
NOTE: The data set WORK.COMPLETE22 has 750108 observations and 77 variables.
NOTE: DATA statement used (Total process time):
      real time           1.82 seconds
      cpu time            0.45 seconds


4    Data temp (drop=z);
5    set work.complete22;
6    /* recoding age */
7    if AGE_KEY >=0 and AGE_KEY <= 4 then agegroup=1;
8    if  AGE_KEY >=5  and AGE_KEY <= 9 then agegroup=2;
9    if  AGE_KEY >=10 and AGE_KEY <= 14 then agegroup=3;
10   if  AGE_KEY >=15  and AGE_KEY <= 19 then agegroup=4;
11   if  AGE_KEY >=20  and AGE_KEY <= 24 then agegroup=5;
12   if  AGE_KEY >=25  and AGE_KEY <=29 then agegroup=6;
13   if  AGE_KEY >=30  and AGE_KEY <= 34 then agegroup=7;
14   if  AGE_KEY >=35  and AGE_KEY <= 39 then agegroup=8;
15   if  AGE_KEY >=40  and AGE_KEY <= 44 then agegroup=9;
16   if  AGE_KEY >=45  and AGE_KEY <= 49 then agegroup=10;
17   if  AGE_KEY >=50  and AGE_KEY <= 54 then agegroup=11;
18   if  AGE_KEY >=55  and AGE_KEY <= 59 then agegroup=12;
19   if  AGE_KEY >=60  and AGE_KEY <= 64 then agegroup=13;
20   if  AGE_KEY >=65  and AGE_KEY <= 69 then agegroup=14;
21   if  AGE_KEY >=70  and AGE_KEY <= 74 then agegroup=15;
22   if  AGE_KEY >=75  and AGE_KEY <= 79 then agegroup=16;
23   if  AGE_KEY >=80  and AGE_KEY <= 84 then agegroup=17;
24   if  AGE_KEY >=85 then agegroup=18;
25   else if AGE_KEY =. then agegroup =19;
26
27   /*    *primary dx only;*/
28
29   array DXS[18] $ dx1-dx18;
30   CO_FLAG = 0;
31
32   do z= 1 to 18;
33
34   if substr(DXS {z},1,5) IN:('T5801' 'T5804' 'T5811' 'T5814' 'T5891' 'T5894' 'T5802’ ‘T5803’
34 ! ‘T5812’ ‘T5813’)
35
36               or substr(DXS {z},1,6)IN:(‘T582X2’ ‘T582X3’ ‘T588X3’ ‘T5892' 'T582X1' 'T582X4'
36 ! 'T588X1' 'T588X4')
37
38                                    or DXS{z} in: (‘T5882X2’)
                                                     -
                                                     22
                                                     76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
              a datetime constant, a missing value, iterator, (.

ERROR 76-322: Syntax error, statement will be ignored.

39
40               then CO_FLAG = 1;
41
42               leave;
43
44               END;
45
46               run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEMP may be incomplete.  When this step was stopped there were 0
         observations and 79 variables.
NOTE: DATA statement used (Total process time):
      real time           0.09 seconds
      cpu time            0.04 seconds

Tom
Super User Tom
Super User

So now you can SEE that the underscore is underneath that non-ASCII character you have on that line.

Tom_0-1724857963355.png

 

Just edit your code so that you are using actual quotes and not typesetting (word processing) special characters.

ballardw
Super User

I think the actual problem starts here:

 if substr(DXS {z},1,5) IN:('T5801' 'T5804' 'T5811' 'T5814' 'T5891' 'T5894' 'T5802 ‘T5803’

The first quote from 'T5802 doesn't find a match until

 

36               or substr(DXS {z},1,6)IN:(‘T582X2’ ‘T582X3’ ‘T588X3’ ‘T5892' 'T582X1' 'T582X4'

If the mismatched quote hadn't appeared as the second for T5802 the next value, T5803 would have shown the same error.

So many of the comparisons are going to fail because of the mismatching of the programming quotes and the "curly" quotes.

These curly quotes typically come from copying text from a different text source.

 

Kurt_Bremser
Super User

Those curly quotes which cause your trouble might come from some editing in a word processor; do not use such for coding.

If you're not happy with the SAS-supplied editors, use something like Notepad++ or a coding environment, but never Word or similar.

FreelanceReinh
Jade | Level 19

Hello @Fadams12 (and @fadamso12) and welcome to the SAS Support Communities!

 

In addition to the "curly quotes" issue there seems to be a logic error in your code, which the SAS log does not complain about:


@fadamso12 wrote:
40               then CO_FLAG = 1;
41
42               leave;
43
44               END;

The LEAVE statement is executed unconditionally. Hence, the IF condition is checked for z=1 only. Most likely, your intention was to write

 then do;
   CO_FLAG = 1;
   leave;
 end;

before the closing END statement of the DO loop, so that the checks are applied to z=2, 3, ... as well, until the first value satisfying the IF condition (if any).

fadamso12
Calcite | Level 5

Hello everyone, 

Thank you all for the support. This is my first using the array and doing loops, so bear with me. I want this code to the checks applied to z=2, 3, so should I remove the LEAVE? Also, after correcting the issue with quotes, now it's a loop, not closed. I have tried to end and run twice, but both do not work. 

258  Data temp (drop=z);
259  set work.complete22;
260  array DXS[18] $ dx1-dx18;
261  CO_FLAG = 0;
262
263  do z= 1 to 18;
264
265  if substr(DXS {z},1,5) IN:('T5801' 'T5804' 'T5811' 'T5814' 'T5891' 'T5894' 'T5802' 'T5803'
265! 'T5812' 'T5813')
266
267              or substr(DXS {z},1,6)IN:('T582X2' 'T582X3' 'T588X3' 'T5892' 'T582X1' 'T582X4'
267! 'T588X1' 'T588X4')
268
269                                   or  DXS{z} in:('T5882X2')
270
271              then do;
272              CO_FLAG = 1;
273              leave;
274              end;
275              run;

275              run;
                    -
                    117
ERROR 117-185: There was 1 unclosed DO block.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEMP may be incomplete.  When this step was stopped there were 0
         observations and 78 variables.
WARNING: Data set WORK.TEMP was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


276              end;
                 ---
                 180

ERROR 180-322: Statement is not valid or it is used out of proper order.

277              run;

fadamso12
Calcite | Level 5

Can someone please help me fix this code loop? It

Data temp (drop=z); 
set work.complete22;
array DXS[18] $ dx1-dx18;
CO_FLAG = 0;

do z= 1 to 18;

if substr(DXS {z},1,5) IN:('T5801' 'T5804' 'T5811' 'T5814' 'T5891' 'T5894' 'T5802' 'T5803' 'T5812' 'T5813')

            or substr(DXS {z},1,6)IN:('T582X2' 'T582X3' 'T588X3' 'T5892' 'T582X1' 'T582X4' 'T588X1' 'T588X4')

                                 or  DXS{z} in:('T5882X2')

        
		then do CO_FLAG = 1;
         leave;
			end;
			end;
           	run;

is not working. It only flags Zero's 

PaigeMiller
Diamond | Level 26

Can you please show us a small portion of the data that should not produce a zero? From now on, can you please show us the log as we requested earlier?

--
Paige Miller
FreelanceReinh
Jade | Level 19

@fadamso12 wrote:
		then do CO_FLAG = 1;
         leave;
			end;

You omitted the semicolon after the DO statement, which changes the meaning of the code.

Sarath_A_SAS
Obsidian | Level 7

Can you try this and see if it works for you.  

Corrections made:

  1. Replaced curly braces {} with square brackets [] for referencing array elements.
  2. Fixed the single quotes around the string constants (changed them from “curly” quotes to straight quotes).
  3. Ensured the IN operator was used properly by separating the values with commas and enclosing them in parentheses.

This should resolve the syntax errors you were encountering.

 

Data temp (drop=z);
    set work.complete22;
    array DXS[18] $ dx1-dx18;
    CO_FLAG = 0;

    do z= 1 to 18;
        if substr(DXS[z],1,5) IN ('T5801', 'T5804', 'T5811', 'T5814', 'T5891', 'T5894', 'T5802', 'T5803', 'T5812', 'T5813') 
            or substr(DXS[z],1,6) IN ('T582X2', 'T582X3', 'T588X3', 'T5892', 'T582X1', 'T582X4', 'T588X1', 'T588X4') 
            or DXS[z] in ('T5882X2') then CO_FLAG = 1;
        leave;
    end;
run;

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 46 replies
  • 2295 views
  • 10 likes
  • 8 in conversation