BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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

 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Bal23
Lapis Lazuli | Level 10

 

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

data_null__
Jade | Level 19

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
FreelanceReinh
Jade | Level 19

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

 

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
  • 11928 views
  • 1 like
  • 4 in conversation