I have several databases, one per geographical variables, that I want to append in the end. I am doing some data steps on them. As I have large databases, I select only the variables I need when I first call each table. But on tables in which one variable always equals 0, the variable is not in the table.
So when I select my (keep=var) in a for loop, it works fine if the variable exists, but it produces an error in the other case, so that these tables are ignored.
do i=1 to 10 ;
data temp;
set area_i(keep= var1 var2);
run;
proc append base=want
data=temp force;run;
Is there a simple way to tackle that ?
DKRICOND=ERROR | WARN | WARNING | NOWARN
DKROCOND=ERROR | WARN | WARNING | NOWARN
You can suppress the generation of an ERROR with options nodsfnerr;
I did not find any occurence of your option :smileyconfused:
Brain fart. SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition describes it, but it is used to suppress errors caused by nonexisting datasets.
Xia Keshan has the correct solution.
DKRICOND=ERROR | WARN | WARNING | NOWARN
DKROCOND=ERROR | WARN | WARNING | NOWARN
It worked, thanks a lot !
You could also create an empty template dataset, and set this with your data so the variables you require are never missing:
proc sql;
create table TEMPLATE (VAR1 char(200),VAR2 char(200));
quit;
data temp (keep=var1 var2) ;
set area_i template;
run;
That way temp will always have var1 and var2.
I am afraid it will add too much time, as it adds one dataset creation. I have millions of observations, so this might matters.
Sorry, I was going on the example you had given. If you are dealing with large amount of datasets then you want a better way of working. Check the metadata and then generate the program from that. Whilst there are ways to get around warnings and such like, they do come out for a reason. IMO I would try to fix these rather than remove them from the log. E.g.
proc sql;
select distinct NAME
into :TABLE1 separated by " "
from SASHELP.VCOLUMN
where LIBNAME="WORK"
and MEMNAME="DATASET"
and NAME in ("VAR1","VAR2");
select distinct NAME
into :TABLE2 separated by " "
from SASHELP.VCOLUMN
where LIBNAME="WORK"
and MEMNAME="DATASET"
and NAME in ("VAR1","VAR2");
/* Note, probably easier ways to get the macro lists I am typing this quickly */
quit;
data want;
set table1 (keep=id &table1.)
table2 (keep=id &table2.);
run;
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 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.