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

Attached spreadsheet has two input files (File_1 & File_2) and a desired result. 

I need to create a table with the Quarter Per School to be added to File_1 for a date in the year

according to date range (File_2) for that school.

Cannot join on the schoolid so assuming I need to write a proc.

Help!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I think a SQL join here is straight forward:

 

proc sql;
create table want as 
select a.*, coalescec(b.quarter, 'NA') as Quarter
from file_1 as a
left join file_2 as b
on a.calendar_date between b.date1 and b.date2
and a.school=b.schoolID;
quit;

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Can you illustrate your problem with a small set of data in a post. Many users cannot download XLSX files due to security restrictions.

carmendee
Obsidian | Level 7

Thanks Reeza!

 

File_1

CALENDAR_DATE             SCHOOL

04Mar2017 0:00:00           340326

04Mar2017 0:00:00           340330

04Mar2017 0:00:00           340504

11Feb2017 0:00:00           340326

11Feb2017 0:00:00           340330

11Feb2017 0:00:00           340504

10Jan2017 0:00:00           340326

10Jan2017 0:00:00           340330

10Jan2017 0:00:00           340504

01Jul2016 0:00:00            340326

01Jul2016 0:00:00            340330

01Jul2016 0:00:00            340504

File_2

Quarter   DATE1                             DATE2                           SCHOOLID

Q1          29Aug2016 0:00:00          08Nov2016 0:00:00         340326

Q1          29Aug2016 0:00:00          07Nov2016 0:00:00         340330

Q1          29Aug2016 0:00:00          08Nov2016 0:00:00         340504

Q2          09Nov2016 0:00:00          20Jan2017 0:00:00         340326

Q2          09Nov2016 0:00:00          21Jan2017 0:00:00         340330

Q2          09Nov2016 0:00:00          20Jan2017 0:00:00         340504

Q3          24Jan2017 0:00:00           02Apr2017 0:00:00         340326

Q3          24Jan2017 0:00:00           02Apr2017 0:00:00         340330

Q3          24Jan2017 0:00:00           02Apr2017 0:00:00         340504

Q4          03Apr2017 0:00:00           07Jun2017 0:00:00         340330

Q4          03Apr2017 0:00:00           08Jun2017 0:00:00         340326

Q4          03Apr2017 0:00:00           08Jun2017 0:00:00         340504

 

Results

CALENDAR_DATE          SCHOOL             Quarter

04Mar2017 0:00:00         340326                 Q3

04Mar2017 0:00:00         340330                 Q3

04Mar2017 0:00:00         340504                 Q3

11Feb2017 0:00:00         340326                 Q3

11Feb2017 0:00:00         340330                 Q3

11Feb2017 0:00:00         340504                 Q3

10Jan2017 0:00:00         340326                 Q2

10Jan2017 0:00:00         340330                 Q2

10Jan2017 0:00:00         340504                 Q2

01Jul2016 0:00:00          340326                 NA

01Jul2016 0:00:00          340330                 NA

01Jul2016 0:00:00          340504                 NA

Reeza
Super User

I think a SQL join here is straight forward:

 

proc sql;
create table want as 
select a.*, coalescec(b.quarter, 'NA') as Quarter
from file_1 as a
left join file_2 as b
on a.calendar_date between b.date1 and b.date2
and a.school=b.schoolID;
quit;

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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