/*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;
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.
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.
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.