BookmarkSubscribeRSS Feed
PujaDas
Calcite | Level 5

Hi Community,

 

I am facing an systax error and expecting something after running this. Please guide me what is the correct one

 

compute Index_Id;

    if Index_Id = '0' then

call define(_row_,"style","style={just=1 font face=Arial font_style=italic font_size=2}");

else

if((Caol1=(' ' | '0.00%') and col2=(' ' | '0.00%'))

then do;

col1=' ';

col2=' ';

end;

endcomp;

 

Please help me out.

10 REPLIES 10
Shmuel
Garnet | Level 18

You posted only a part of your program code.

 

You should post, also, the log with the syntx error you got.

 

Or maybe your error is:

    if((Caol1=(' ' | '0.00%') and col2=(' ' | '0.00%'))

should it be col1 instead Caol1 ???

PujaDas
Calcite | Level 5

Sorry for creating the confusion.. i am changing no its col1.. i have done the typing mistake here..i have attachd the log here..


20161214_140328.jpg
Kurt_Bremser
Super User

The ERROR points to the "then" keyword, indicating a problem with the condition. Counting your parentheses I see 11 opening, but only 10 closing parentheses.

 

Once again you stumble into the "spaghetti code hole". As soon as logical code segments go beyond one line, proper use of indentation and linebreaks to separate the elements is a MUST!

 

Also make use of a feature of the enhanced editor: when putting the cursor to a closing parenthesis, the editor will show you the opening one that it thinks is paired with it.

 

Seeing that you only have and's in your condition, most of your parentheses are unnecessary, anyway. Parentheses to separate condition elements are only necessary when "or" and "and" are mixed and the rule "and goes before or" has to be circumvented.

Kurt_Bremser
Super User

And, BTW: just copy/paste the log into a {i} subwindow here; downloading the image takes time, and one can't copy/paste code from an image for testing/editing. Don't expect us to type code for you when it's absolutely not necessary.

Kurt_Bremser
Super User

Posting the log with the syntax error in a {i} window would greatly help 😞

 

From your earlier posts, I think that caol1 is not present in the dataset. And the only variables that can be used in the compute statement are group or order variables for a compute target.

PujaDas
Calcite | Level 5

20161214_140328.jpg
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What the chaps above are asking is that you don't post pictures (or other documents) but use simple copy and paste functionality to copy the text from your program into the post you are writing.  It is annoying and difficult to use pictures for anything.  

You can also use the code window function in your posts.  Above where you type replies there is a tool bar containing {i}, and other tools icons.  Use this to post code and logs as it stands out and keeps formatting.

 

Now onto your problem.  As mentioned above, you have unbalanced quote, bracket or other containing special characters.  We can't tell really from that picture where it is.  So step through your code, check each line works.  Count that the number of ) = number of these (.

 

This is could debugging and is something you will do all the time in programming.  Note you can comment out section of code by highlighting and pressing cntrl + shift + / and uncomment with cntrl + shift + \.  makes debugging easier.

Astounding
PROC Star

Using the same style of syntax that you have been, your code is missing a closing parenthesis:

 

else if ((One_Day_Un_Return2=(' ' | '0.00%'))

 

However, once that is cleared up, there are many more issues with the code.  I would guess that your intention is to check each variable to see whether it is either blank or contains the text "0.00%".  If that's the case, the proper syntax would be:

 

else if One_Day_Un_Return2 in (' ', ' 0.00%') ......;

 

If your intention is something else you will have to add some details about it.  But even the fixed code (adding the parenthesis) will not run.

 

 

PujaDas
Calcite | Level 5

Hi,

 

Thank you for your support.

Actually the requirement is to check the value of a column if '0.00%' then it would be blank.

First of all to check for a condition that if the value of a column is 0 then make it as '0.00%'. I have done it to make it as char fist using put() then || with percentage.Its working fine.

For the next case While I am trying to check if the column value is '0.00%' then make it as blank,dats not working. I feel that when I am trying to check if the value is equal to '0.00%' then make it as col1=' ' ,it simply make it as blank || %. which cant match the condition anymore. thats why expected output is not coming.

can you please help me how to resolve this one??

 

thanks,

Puja

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

If you post some test data in the form of a datastep we could provide working code.  I am unsure as to why you need to convert a value before you check if it is 0 or not?

data want;
  length want_text $20;
  input myval;
  want_text=ifc(myval=0,"",put(myval,percent7.1));
datalines;
0
0.345
;
run;

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!

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
  • 10 replies
  • 1664 views
  • 2 likes
  • 5 in conversation