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

Hi Community,

 

Could you please help me with the following.

 

Below is a test data table and the output I am looking for meets the following conditions:

 

1. Give me the list of accounts that contains the 'AccBal' if 'Date' equals OpenDate and also

2. For those accounts that meet the above condtion give me the 'O_Bal' for Day5

 

DateAccNoAccBal O_BalOpenDate
1-Sep-1812345610,000.0020001-Sep-18
2-Sep-1812345610,000.0020001-Sep-18
3-Sep-1812345610,000.0020001-Sep-18
4-Sep-1812345610,000.0020001-Sep-18
5-Sep-1812345610,000.0020001-Sep-18
6-Sep-1812345610,000.0020001-Sep-18
7-Sep-1812345610,000.0020001-Sep-18
8-Sep-1812345610,000.0020001-Sep-18
9-Sep-1812345610,000.0020001-Sep-18
10-Sep-1812345610,000.0020001-Sep-18
5-Sep-1812345615,000.0030005-Sep-18
6-Sep-1812345615,000.0030005-Sep-18
7-Sep-1812345615,000.0030005-Sep-18
8-Sep-1812345615,000.0030005-Sep-18
9-Sep-1812345615,000.0030005-Sep-18
10-Sep-1812345615,000.0030005-Sep-18

 

Thanks kindly

 

1 ACCEPTED SOLUTION

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

If thats 5 days from the date then something like:

proc sort data=have out=inter nodupkey;
by accno accbal;
where date=opendate;
run;

proc sql;
create table want as
select a.*,
b.accbal as day5
from inter a
left join have b
on a.accno=b.accno
and b.date=a.date+5;
quit;

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

1) 

proc sort data=have out=want nodupkey;
  by accno accbal;
  where date=opendate;
run;

2)

I have no idea what you mean by Day5?

Timbim
Obsidian | Level 7

Hi RW9,

 Day5 meaning the O_Bal on the 5th Calender Day using the 'Date' field.

 

Thanks kindly.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

If thats 5 days from the date then something like:

proc sort data=have out=inter nodupkey;
by accno accbal;
where date=opendate;
run;

proc sql;
create table want as
select a.*,
b.accbal as day5
from inter a
left join have b
on a.accno=b.accno
and b.date=a.date+5;
quit;
Timbim
Obsidian | Level 7

Hi RW9

 

Thanks for your prompt response.

 

The first logic works but the 2nd gives me blank for Day 5. It is the O_Bal that I want at Day5 and not the AccBal. I replaced AccBal as Day5 with O_Bal at Day5 using your logic but getting blanks.

 

Thanks kindly.

ballardw
Super User

@Timbim wrote:

Hi RW9

 

Thanks for your prompt response.

 

The first logic works but the 2nd gives me blank for Day 5. It is the O_Bal that I want at Day5 and not the AccBal. I replaced AccBal as Day5 with O_Bal at Day5 using your logic but getting blanks.

 

Thanks kindly.


Show the code you ran and the log.

Are your dates actual SAS date values or character values masquerading as dates? If so, then the +5 would likely throw an error of some sort.

Timbim
Obsidian | Level 7

Hi Ballard,

 

My sincere apologies. The logic posted by RW9 works however I have about 2 records that giving me blank dates ( with a period sign) instead of the dates. I checked the raw data and it does have dates for those 2 records.

 

My logic is as follows

 

Data bal_startdate (rename=(Date=StartDate) drop=Offset_Bal);

set Daily;

by AccNo;

if first.AccNo;

run;

 

Proc Sql;

Create table Day5_bal as

select a.*,

 

b.offset_Bal,

b.date as Day5,

 

case

when b.date is missing then 'N' else 'Y' end as Day5_Flag

From bal_startdate a

left join Daily b on a.AccNo=b.AccNo and b.date=a.StartDate+5;

quit;

 

 

The results are as I want however I've picked 2 accounts that having missing 'b.date as Day 5' when there is a date in the raw data.

 

Thanks for your help.

Timbim
Obsidian | Level 7

Thanks RW9 for your this logic.

 

I revisited my data and tried your logic again and it works.

 

Thanks kindly.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2295 views
  • 0 likes
  • 3 in conversation