BookmarkSubscribeRSS Feed
J_C
Calcite | Level 5 J_C
Calcite | Level 5

Hi,

I have not been programming for long and below is what I would like to do, but clearly the syntax is wrong.

proc sql;

create table good as

select *

from (case when date<'10/31/2014' then table1

               else table2)

;

quit;

In other words, depending on the date, I either want to pick table 1 or table 2.

Another way of doing it could be name change, as in..... if date<'10/31/2014' then rename table1 to good else rename table2 to good.

Thanks in advance,

J-C

5 REPLIES 5
stat_sas
Ammonite | Level 13

Hi,

Something like this may be useful in selecting observations based on condition.

proc sql;

create table good as

select *

from table1 where date<'31OCT2014'd

union all

select *

from table2 where date>='31OCT2014'd;

quit;

art297
Opal | Level 21

If date is referring to today's date, you could use something like the following:

%macro doit;

  proc sql;

    create table good as

      select *

        from

          %if date()<'31OCT2014'd %then table1;

          %else table2;

    ;

  quit;

%mend;

%doit

J_C
Calcite | Level 5 J_C
Calcite | Level 5

Thanks for your input and came up with this not along after posting the question.

Can you let me know if this works as well (obviously less efficient then yours)?

Fyi, &date. is already defined.

data _test;

if &date.<September then table_name= 'table 1';

else table_name='table 2';

run;

proc sql no print;

select table_name into:view_select

from _test;

quit;

proc sql;

create table good as

select *

from &view_select.

;

quit;

It seems to work so far, but do you see a case where it might fail?

Thanks,

J-C

art297
Opal | Level 21

Not sure what you're comparing with:

if &date.<September


Reeza
Super User

In addition to what Art has noted:

1. Dates in SAS for comparison need to be in the form: "DDMONYYYY"d i.e. "01Jan2014"d, so your date of 10/31/2014 may need to be transformed.

2. You can create the macro variable directly in the first data step using call symput/x

Assuming &date is a SAS date then you could do something like the following

data _test;

if month(&date.)<9 then call symputx('view_table', 'table 1)';

else call symputx('view_table', 'table 2');

run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1048 views
  • 0 likes
  • 4 in conversation