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

Hi SAS community :smileygrin:

I'm struggling to find an efficient way to do the following:

Say I have the table

Acc_NrTransaction_DateTransaction_CodeTransaction_Amount
a101JUL2012:06:00:00111500
a101JUL2012:12:32:05111400
a201JUL2012:07:23:23222600
a102JUL2012:05:33:20111100
a201JUL2012:13:43:15111400
a302JUL2012:08:32:10222300
a302JUL2012:09:32:30222500

So the output I want should be in the form of:

Acc_NrTransaction_DateTransaction_CodeTransaction_Amount
a101JUL2012:06:00:00111500
a201JUL2012:07:23:23222600
a102JUL2012:05:33:20111100
a302JUL2012:08:32:10222500

I have tried the following code:

proc sort=old;

by Transaction_Date Acc_Nr;

run;


data wanted;

set old;

by  Transaction_Date;

if first.Acc_Nr then output;

else delete;

run;


But this does not seem to work (Variable first.Acc_Nr is uninitialized) which is understandable.


Do you have an efficient approach to this problem?


Thank you! :smileygrin:



dansaction_Date

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

first. and last. are only generated for variables in the "by" list.

Try this:

data int;

set old;

int_day = datepart(Transaction_Date);

run;

proc sort data=int;

by Acc_Nr Transaction_Date;

run;

data wanted (drop=int_day);

set int;

by Acc_Nr int_date;

if first.int_date;

run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

first. and last. are only generated for variables in the "by" list.

Try this:

data int;

set old;

int_day = datepart(Transaction_Date);

run;

proc sort data=int;

by Acc_Nr Transaction_Date;

run;

data wanted (drop=int_day);

set int;

by Acc_Nr int_date;

if first.int_date;

run;

mjheever
Obsidian | Level 7

KurtBremser wrote:

first. and last. are only generated for variables in the "by" list.

Thank you for clearing this up Kurt.

The code you provided works perfectly :smileygrin: :smileygrin: :smileygrin:...

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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