DATA Step, Macro, Functions and more

If/Then statement /greyed out portions

Accepted Solution Solved
Reply
Super Contributor
Posts: 383
Accepted Solution

If/Then statement /greyed out portions

I'm puzzled with greyed out portions in below code for if then logic. You know why? See screen shots of log and the way it's greyed out.

 

if then.pnglog if then.png

 

data agebins;
do agecat=1 to 14 by 1;
output;
end;
run;

data agebins1; set agebins; if agecat=1 then agerisk=0.00048; if agecat=2 then agerisk=0.001161; if agecat=3 then agerisk=0.000859; if agecat=4 then agerisk=0.001314;  if agecat=5 then agerisk=0.00208; if agecat=6 then agerisk=0.00311; if agecat=7 then agerisk=0.005029;  if agecat=8 then agerisk=0.007975;  if agecat=9 then agerisk=0.012361;  if agecat=10 then agerisk=0.01817; if agecat=11 then agerisk=0.025729; if agecat=12 then agerisk=0.035717; if agecat=13 then agerisk=0.043564; if agecat=14 then agerisk=0.152939; run;

Accepted Solutions
Solution
‎02-03-2018 02:09 PM
Community Manager
Posts: 3,461

Re: If/Then statement /greyed out portions

[ Edited ]

There is nothing wrong with your program as you've pasted here.  But in your editor, you might have a rogue character at the end of the line where the error occurs (before the "gray" IF).  Move the cursor to the end of that line to see what's there.  Might also be a non-visible control character.  You could copy/paste your code into a program like Notepad++ and View all Characters.  I tried that with what you supplied -- nothing suspicious.  And your code block runs fine in SAS OnDemand for Academics (where I tried it).

View solution in original post


All Replies
Solution
‎02-03-2018 02:09 PM
Community Manager
Posts: 3,461

Re: If/Then statement /greyed out portions

[ Edited ]

There is nothing wrong with your program as you've pasted here.  But in your editor, you might have a rogue character at the end of the line where the error occurs (before the "gray" IF).  Move the cursor to the end of that line to see what's there.  Might also be a non-visible control character.  You could copy/paste your code into a program like Notepad++ and View all Characters.  I tried that with what you supplied -- nothing suspicious.  And your code block runs fine in SAS OnDemand for Academics (where I tried it).

Super Contributor
Posts: 383

Re: If/Then statement /greyed out portions

Posted in reply to ChrisHemedinger
I copied the code from notepad++ where it might have taken invisible characters from there? I backspaced and took spaces to fix as you suggested. Worked it out! Thanks a lot Chris!
Super User
Posts: 13,939

Re: If/Then statement /greyed out portions


Cruise wrote:
I copied the code from notepad++ where it might have taken invisible characters from there? I backspaced and took spaces to fix as you suggested. Worked it out! Thanks a lot Chris!

Most likely sources of invisible characters would be from files in another format such as word processors or websites.

Super User
Super User
Posts: 8,276

Re: If/Then statement /greyed out portions

[ Edited ]

You can also let a SAS data step show you want strange characters are in your program.  Use the CARDS4 (aka DATALINES4) statement with the LIST statement.

 

For example you could find that you have an embedded carriage return ('0D'x) character like in this example.

1860  data _null_;
1861    input; list;
1862  cards4;

RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1863        data agebins;
1864        do agecat=1 to 14 by 1;
1865        output;
1866        end;
1867        run;
1868
1869        data agebins1; set agebins;
1870        if agecat=1 then agerisk=0.00048;

1871CHAR    if agecat=2 then agerisk=0.001161;.
    ZONE    66266666733276662666767633233333330222222222222222222222222222222222222222222222
    NUMR    960175314D20485E0175293BD0E001161BD000000000000000000000000000000000000000000000
1872        if agecat=13 then agerisk=0.043564;
1873        if agecat=14 then agerisk=0.152939;
1874        run;
1875  ;;;;

Or some other invisible character.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 162 views
  • 4 likes
  • 4 in conversation