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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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