BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

Hello

In the following code there is a field in keep that doesnt exost in the data set. (Field called color in my code)

Using options dkricond=warning   prevent error and the code is running well.

My question- Is there a way to  prevent warning message?

 

The issue is that I wrote code that other people should run.

It might happend that in the source data set some of fields will not exist and then I want that the code still run (no error).

I also prefer that no warning occur due to this issue.

If other issues arrise then of course I want that they appear i warning message

options dkricond=warning;
data cars;
set sashelp.cars(KEEP=model  make  invoice color);
Run;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Ronein wrote:
Let's say i want to prevent warning only on specific code and when continue other codes warning will behave normally

@Tom already shared how this can be done.

 

Another option is to build your list of vars to keep dynamically to only contain variable names that actually exist in your source table.

proc sql noprint;
  select name into :keeplist separated by ' '
  from dictionary.columns
  where libname='SASHELP' and memname='CARS'
    and upcase(name) in ('MODEL','MAKE','INVOICE','COLOR')
  ;
quit;
 
data cars;
  set sashelp.cars(KEEP=&keeplist);
run;

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

Just remember the current setting so you can change it back.

%let optsave=%sysfunc(getoption(dkicond));
options dkricond=NOwarning;
data cars;
set sashelp.cars(KEEP=model  make  invoice color);
run;
option dkricond=&optsave;
ballardw
Super User

@Ronein wrote:

 

The issue is that I wrote code that other people should run.

It might happend that in the source data set some of fields will not exist and then I want that the code still run (no error).

If you are writing the code for other people to run the I would say that it is also your job to verify if the variables exist in the data sets used and to modify the code so that there are no such  issues.

 

Easy enough to check existence of variables for SAS data sets, I suspect there are at least 20 or 30 threads just on this forum related to such. If your data is external then that may be a bit more complicated.

 

Modifying the code to use a verified list of variables may be much more complicated depending on how you are using the variables. There are many places that missing variables are critical failures and just turning off warnings will not allow the code to run at all much less "with no error". You may have to provide some examples of other examples of where these possibly missing variables may occur if other than in a Keep option or statement. 

Ronein
Onyx | Level 15
For some periods the field doesn't exist and gor other exists...I just want to prevent warning here. What is the way??
Quentin
Super User

@Ronein wrote:
For some periods the field doesn't exist and gor other exists...I just want to prevent warning here. What is the way??

Please see Tom's answer, and if his answer does not suffice, please explain why it doesn't meet your need.

Kurt_Bremser
Super User

If it's not always there, then it's of no use for proper analysis, which also means there's no reason to explicitly KEEP it.

If, OTOH, you really need it, then you will have to infer values for the missing periods, which also means dynamic code where you omit the KEEP and therefore do not need to suppress the WARNING/ERROR. 

Ronein
Onyx | Level 15
Let's say i want to prevent warning only on specific code and when continue other codes warning will behave normally
Patrick
Opal | Level 21

@Ronein wrote:
Let's say i want to prevent warning only on specific code and when continue other codes warning will behave normally

@Tom already shared how this can be done.

 

Another option is to build your list of vars to keep dynamically to only contain variable names that actually exist in your source table.

proc sql noprint;
  select name into :keeplist separated by ' '
  from dictionary.columns
  where libname='SASHELP' and memname='CARS'
    and upcase(name) in ('MODEL','MAKE','INVOICE','COLOR')
  ;
quit;
 
data cars;
  set sashelp.cars(KEEP=&keeplist);
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 578 views
  • 3 likes
  • 6 in conversation