Would anybody provide a sample code? I only see someone mentioned it, but when i add "options msglevel-1", it always shows error.
Can anybody show a sample code? Thanks.
Hi @Bal23,
I set msglevel=I in my autoexec.sas, primarily because I want to see the "INFO" messages from MERGE statements about (inadvertently) overwritten variables. These would not occur in the log with the default setting msglevel=N. Here is an example that shows why this can be useful (please focus on the third datastep):
options msglevel=I;
data test1;
do a=1 to 3;
do _n_=1 to 3;
b=a/10;
output;
end;
end;
proc print;
run;
data test2;
input a b;
cards;
1 10
2 20
3 30
;
data new;
merge test1
test2;
by a;
proc print;
run;
Thanks to the option setting, the log for the last data step contains the following message:
INFO: The variable b on data set WORK.TEST1 will be overwritten by data set WORK.TEST2.
This makes me aware that possibly something unwanted has happened with variable b. As you can see, the value of b in the first observation of each BY group has been updated ("overwritten") with the value from dataset TEST2, but the remaining observations still have their old value from TEST1. This mixture of old and new values was most likely not intended.
So, typically you would strive to avoid this INFO message, although msglevel=I, by careful programming. In the example above it could make sense to add the (drop=b) dataset option to test1 in the last data step (depending on the intended result).
In the rare occasions where the overwriting is acceptable and the INFO message cannot be avoided otherwise for some reason, you may want to set msglevel=N for the affected part of the program (and reset it to I afterwards).
You get an error as it should be:
options msglevel=1;
not
options msglevel-1;
For use check the SAS docs:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000279149.htm
Sorry I did write it wrong. But actually I did get an error message below. This is the reason why I am asking for a sample code. Thanks.
961 options msglevel=1;
--------
14
ERROR 14-12: Invalid option value 1 for SAS option MSGLEVEL.
962
I think you are confusing 1 and I as in
33 proc options option=msglevel define expand; 34 run; SAS (r) Proprietary Software Release 9.4 TS1M3 MSGLEVEL=N Option Definition Information for SAS Option MSGLEVEL Group= LOGCONTROL Group Description: LOGCONTROL Description: Specifies the level of detail in SAS log messages. Type: The option value is of type CHARACTER Maximum Number of Characters: 1 Casing: The option value is retained uppercased Quotes: If present during "set", start and end quotes are removed Parentheses: The option value cannot be enclosed within parentheses. Expansion: Environment variables, within the option value, are not expanded Number of valid values: 2 Valid value: I Valid value: N When Can Set: Startup or anytime during the SAS Session Restricted: Your Site Administrator can restrict modification of this option Optsave: PROC Optsave or command Dmoptsave will save this option
Hi @Bal23,
I set msglevel=I in my autoexec.sas, primarily because I want to see the "INFO" messages from MERGE statements about (inadvertently) overwritten variables. These would not occur in the log with the default setting msglevel=N. Here is an example that shows why this can be useful (please focus on the third datastep):
options msglevel=I;
data test1;
do a=1 to 3;
do _n_=1 to 3;
b=a/10;
output;
end;
end;
proc print;
run;
data test2;
input a b;
cards;
1 10
2 20
3 30
;
data new;
merge test1
test2;
by a;
proc print;
run;
Thanks to the option setting, the log for the last data step contains the following message:
INFO: The variable b on data set WORK.TEST1 will be overwritten by data set WORK.TEST2.
This makes me aware that possibly something unwanted has happened with variable b. As you can see, the value of b in the first observation of each BY group has been updated ("overwritten") with the value from dataset TEST2, but the remaining observations still have their old value from TEST1. This mixture of old and new values was most likely not intended.
So, typically you would strive to avoid this INFO message, although msglevel=I, by careful programming. In the example above it could make sense to add the (drop=b) dataset option to test1 in the last data step (depending on the intended result).
In the rare occasions where the overwriting is acceptable and the INFO message cannot be avoided otherwise for some reason, you may want to set msglevel=N for the affected part of the program (and reset it to I afterwards).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.