DATA Step, Macro, Functions and more

when MSGlevel=1 is used and how is it used? How to reset? Where to add?

Accepted Solution Solved
Reply
Super Contributor
Posts: 345
Accepted Solution

when MSGlevel=1 is used and how is it used? How to reset? Where to add?

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.

 

 


Accepted Solutions
Solution
‎02-18-2016 02:52 PM
Trusted Advisor
Posts: 1,117

Re: when MSGlevel=1 is used and how is it used? How to reset? Where to add?

Hi @wenling,

 

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

 

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: when MSGlevel=1 is used and how is it used? How to reset? Where to add?

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

Super Contributor
Posts: 345

Re: when MSGlevel=1 is used and how is it used? How to reset? Where to add?

 

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

Respected Advisor
Posts: 3,799

Re: when MSGlevel=1 is used and how is it used? How to reset? Where to add?

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
Solution
‎02-18-2016 02:52 PM
Trusted Advisor
Posts: 1,117

Re: when MSGlevel=1 is used and how is it used? How to reset? Where to add?

Hi @wenling,

 

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

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 446 views
  • 1 like
  • 4 in conversation