SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aboiron
Calcite | Level 5

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

DKRICOND=ERROR | WARN | WARNING | NOWARN

DKROCOND=ERROR | WARN | WARNING | NOWARN

View solution in original post

8 REPLIES 8
Aboiron
Calcite | Level 5

I did not find any occurence of your option :smileyconfused:

Ksharp
Super User

DKRICOND=ERROR | WARN | WARNING | NOWARN

DKROCOND=ERROR | WARN | WARNING | NOWARN

Aboiron
Calcite | Level 5

It worked, thanks a lot !

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Aboiron
Calcite | Level 5

I am afraid it will add too much time, as it adds one dataset creation. I have millions of observations, so this might matters.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3882 views
  • 7 likes
  • 4 in conversation