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.
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;
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).
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).
@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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.