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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Cruise
Ammonite | Level 13
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!
ballardw
Super User

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

Tom
Super User Tom
Super User

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1429 views
  • 4 likes
  • 4 in conversation