Desktop productivity for business analysts and programmers

Tell SAS to ignore error messages

Reply
Contributor
Posts: 35

Tell SAS to ignore error messages

Folks, 

 

I'm attempting to merge a number of datasets together, however, prior to this I need to do some cleaning up. I only want to keep certain variables so I'm using the (keep= ) option. 

 

I've create a macro variable to desginate what variables I want to keep across all my different datasets. Unforunately however, not all variables are in all datasets. Thus when I run the data step, which includes a macro I get a number of errors as the variables I tell  sas to keep are not in the dataset (they are in a number of different datasets). 

 

Is there a a soloution to this. For reference here is a sample of the code I'm using. 

 

%let year = 2014p /*(Points to the new folder)*/;
%let yeara = 2014 /*(Points to the correct year within the folder)*/ ;

%let vars = (keep= profit sales gender region);


data DETAILS&yeara; set itsd.DETAILS&yeara &vars;

data director&yeara; set itsd.director&yeara;&vars;run;

Initially I thought the 

 

OPTIONS NOSYNTAXCHECK;

Might work before I ran the data step but it doesn't. Any feedback welcome. 

 

Kind regards,

Sean 

Esteemed Advisor
Posts: 6,669

Re: Tell SAS to ignore error messages

Use

options dkricond=nowarn;

right before the relevant steps; don't forget to reset DKRICOND to its initial value afterwards, as you don't want SAS to ignore all such errors.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 1,056

Re: Tell SAS to ignore error messages

On the one hand, the solution that @KurtBremser provided will work perfectly, and is by far the easiest.

 

Another option is to actually build a variable list of the variables that you want that are in your target dataset. Here's an example:

 

Tom

 

/* This is the list of variable names we want */

/* Note that "MadeUpColumn" won't be in the dataset */

data VarsToKeep;

length VarName $32;

input VarName;

cards;

Product

Stores

MadeUpColumn

Inventory

run;

/* This will be the table that we want to keep certain variables from */

data FileWithColumns;

set sashelp.shoes;

run;

/* Get the list of variables in the table */

proc sql;

create table GoodColNames as select name as VarName from dictionary.columns

where libname = "WORK" and memname = "FILEWITHCOLUMNS";

quit;

/* Put the list of variables that we want that are also in the dataset into a macro variable */

proc sql noprint;

select n.VarName into :JoinedCols separated by " "

from GoodColNames n join VarsToKeep v

on n.VarName = v.Varname;

quit;

/* Set up the rest of the keep clause syntax */

%let vars =(keep= &JoinedCols.)%str(Smiley Wink;

%put &vars.;

Ask a Question
Discussion stats
  • 2 replies
  • 138 views
  • 0 likes
  • 3 in conversation