BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yangtaotai
Calcite | Level 5

Hello everyone:

I have a question of joining data tables. Suppose my code will produce three tables A, B, and C and I want to join these three tables together. However, these three tables do not always exist and if  this happens, I just want to join the tables with data. For example, if table A does not exist then join B and C tables together.

I know that if you create a table with all columns but no data in it, you can still join it without error. However, my A, B, C tables are created from a macro and when the empty table will not have any columns.

Therefore, I want to know what is the best practice to handle this situations?

Thank you in advance,

Tao

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, you could conditionally execute parts of the code based on existence of the dataset name in sashelp.vtable.  However, my suggestion would be to create the three tables up front and have your macro append data to them.  That way you know they are always present.  Also important, if some data is not created, does that not mean your logic would fall over, i.e. if you are not getting what you expect, maybe re-think the original idea.  I.e. always know your data, and your process - this is more important than doing some coding.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, you could conditionally execute parts of the code based on existence of the dataset name in sashelp.vtable.  However, my suggestion would be to create the three tables up front and have your macro append data to them.  That way you know they are always present.  Also important, if some data is not created, does that not mean your logic would fall over, i.e. if you are not getting what you expect, maybe re-think the original idea.  I.e. always know your data, and your process - this is more important than doing some coding.

yangtaotai
Calcite | Level 5

Hi RW9,

Thank you for your reply!   I wonder if I literally create a table with columns but no data in it and then my macro append A, B, and C to this temp table and this will guarantee the temp table will always have all the existing records. Not sure if this is what you are describing in your reply.

Tao

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, indeed that is my point.  Just simply create empty tables:

proc sql;

     create table A (id num,avar num);

     create table B (id num,avar num);

     create table C (id num,avar num);

quit;

Then in your macro, rather than creating a dataset, just do:

data a;

     set a some_other data;

run;

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
  • 3 replies
  • 809 views
  • 0 likes
  • 2 in conversation