BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

/*this dataset is to have the following ck letters, CK385,CK386,CK218,CK204

I then will merge this dataset with another as seen below and combine with a comment_code dataset

*/

data Letter_Codes_l;

set letter_codes;

run;

data ID_After_Activation_CFPB; 

merge  ID_After_Activation_CFPB (in = a) 

Letter_Codes_l (keep = ln_no  

CK385 

CK386   

CK218 

CK204 

/* The issue is if one of the variables is missing or null, it will generate the error example

ERROR: The variable CK218 in the DROP, KEEP, or RENAME list has never been referenced. In

This case the CK218 was not present in the letter_codes_l.  Is there a way I can still show all

Variable regardless.  These are to be used in totals later in the code*/

in = b) 

Comment_Codes_1st (keep = ln_no  

IP386 

CP385 

SL385 

RS385 

TR218 

MED218 

AD204

in = c) 

by ln_no; 

if a; 

run

4 REPLIES 4
ballardw
Super User

Besides the issue of expected variables not being there, which is a major bit in my opinion, if the number of variables isn't too large you might change to a KEEP statement for the variables not currently on your DROP list.

Or if you want to drop all of the variables starting with CK you could use CK:, or CK2: CK3: to drop all the variables that start with CK2 and CK3.

data_null__
Jade | Level 19

You can use the SAS system option DKRICOND to allow the variable on the KEEP option without error.  However if you want it created when it doesn't exist that is a different story.  Perhaps those variables should actually be values of a variable and then you don't have to worry about which are missing or not.  Give more details about you what you're doing so someone can suggest a method that's not dependent on variables that might not exist.

data a;
   set sashelp.class(keep=age name x);
   run;

options dkricond=nowarn;
data a;
   set sashelp.class(keep=age name x);
   run;
proc contents data=a varnum;
  
run;
options dkricond=error;
Ksharp
Super User

You can make a macro variable to contains these existed variable , and feed it to KEEP= .

Something like .Not tested.

data Letter_Codes_l;

set letter_codes;

run;

proc sql;

select name into : list separated by ' '

  from dictionary.columns

  where libname='WORK' and memname='LETTER_CODES_1' and name in ('ln_no' 'CK385' 'CK386' 'CK218' 'CK204') ;

quit;

data ID_After_Activation_CFPB;

merge  ID_After_Activation_CFPB (in = a)

Letter_Codes_l (keep = &list );

run;


Kurt_Bremser
Super User

The variable is not "missing or null", it is not there at all, so if you actually need that variable, something severe happened further up in the processing chain and needs to be corrected there. If not needed, drop it from the keep list.

"miising or null" would mean that the variable is there, but does not contain any values.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 820 views
  • 0 likes
  • 5 in conversation