BookmarkSubscribeRSS Feed
radha009
Quartz | Level 8

I want to get the data where date (table 1) matches in the table 2. it show no rows.

 

proc sql;
create table sh1.deployments as
select * from sh1.table2 where Start_Date in (select Date from sh1.table1 where  'Friday');
quit;

 

table1

dayDate
Friday10/18/2019
Saturday10/19/2019
Sunday10/20/2019
Monday10/21/2019

 

table 2:

Request#Release IDAnalystStart DateApp IDState
ABC3191089REL0046421Peter10/18/2019AD4234Review
ABC3204276REL0046421Sam10/18/2019SD4344Draft
ABC3212993REL0047406Robert11/13/2019IR4324Review
ABC3213945REL0046421Peter10/31/2019Ar3345Draft
ABC3217910REL0048398Sam10/20/2019FR3444Draft
ABC3219508REL0048584Robert10/25/2019JY3434Approval
ABC3221591REL0048624Peter10/19/2019AD4234Approval
ABC3221593REL0048625Sam10/26/2019AD4234Approval
ABC3221596REL0048628Robert10/19/2019SD4344Draft
ABC3221612REL0048629Peter11/23/2019AD4234Draft
ABC3222870REL0048624Sam10/18/2019AD4234Approval
ABC3222872REL0048628Robert11/15/2019SD4344Draft
4 REPLIES 4
radha009
Quartz | Level 8

its typo i had 

 

proc sql;
create table sh1.table3 as
select * from sh1.table2 where Start_Date in (select date from sh1.table1 where day='Friday');
quit;

Kurt_Bremser
Super User

Then you have to look at the data.

Is day actually character, or could it be a number formatted to display day names?

Are your dates integer values? If imported from Excel, you might have fractions indicating times hidden.

 

PS: check the spelling of your day variable. 'friday' <> 'Friday'!

ballardw
Super User

When I create data based on your pasted text and run a similar query I get 6 rows in the result.

data work.table1;
input day $ Date :mmddyy10.;
format date mmddyy10.;
datalines;
Friday 10/18/2019 
Saturday 10/19/2019 
Sunday 10/20/2019 
Monday 10/21/2019 
;
 

data work.table2;
   input Request :$10. ReleaseID :$10. Analyst $ Start_date :mmddyy10. AppID $ State $;
   format Start_date mmddyy10.;
datalines;
ABC3191089 REL0046421 Peter 10/18/2019 AD4234 Review 
ABC3204276 REL0046421 Sam 10/18/2019 SD4344 Draft 
ABC3212993 REL0047406 Robert 11/13/2019 IR4324 Review 
ABC3213945 REL0046421 Peter 10/31/2019 Ar3345 Draft 
ABC3217910 REL0048398 Sam 10/20/2019 FR3444 Draft 
ABC3219508 REL0048584 Robert 10/25/2019 JY3434 Approval 
ABC3221591 REL0048624 Peter 10/19/2019 AD4234 Approval 
ABC3221593 REL0048625 Sam 10/26/2019 AD4234 Approval 
ABC3221596 REL0048628 Robert 10/19/2019 SD4344 Draft 
ABC3221612 REL0048629 Peter 11/23/2019 AD4234 Draft 
ABC3222870 REL0048624 Sam 10/18/2019 AD4234 Approval 
ABC3222872 REL0048628 Robert 11/15/2019 SD4344 Draft 
;


proc sql;
   create table work.deployments as
   select * from work.table2 
   where Start_date in (select Date from work.table1 where  'Friday');
quit;

If I use a likely more correct Sql code:

proc sql;
   create table work.deployments as
   select * from work.table2 
   where Start_date in (select Date from work.table1 where day= 'Friday');
quit;

I get 3 rows.

 

I make very sure that your Start_date and Date variables are both actually date values, with no decimal portion as @Kurt_Bremser mentions may happen with data starting from some sources. Or given some folks having a poor habit of referring to datetime values as "dates", make sure that is not the case here. You may have to print some values using a BEST format to check.

If the dates are actually character variables then check closely on there values as well. 

Also make sure that in your data set the variable Day does not have any leading spaces or trailing non-blank characters (null characters for example)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 985 views
  • 3 likes
  • 3 in conversation