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

i have a below dataset 

 

data temp;
input cust dt :date9.;
format dt date9.;
datalines;
1 01apr2021
1 02apr2021
1 10apr2021
2 15apr2021
2 18apr2021
2 20apr2021
2 25apr2021
3 29apr2021
3 03may2021
4 04may2021
;
run;

 

and i want a single entry for each cusotmer with fpd and lpd transactions

 

ex: output should be

cust        fpd                  lpd

1       01apr2021     10apr2021

2       15apr2021     25apr2021

3       29apr2021     03may2021

4      04may2021    04may2021

 

i already have sql query for the same i want the solution in data step. Thanks in advance!!

 

sql query :

proc sql;
select cust,min(dt) as fpd format date9.,max(dt) as lpd format date9. from temp
group by cust;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Assuming the data has been sorted .

 


data temp;
input cust dt :date9.;
format dt date9.;
datalines;
1 01apr2021
1 02apr2021
1 10apr2021
2 15apr2021
2 18apr2021
2 20apr2021
2 25apr2021
3 29apr2021
3 03may2021
4 04may2021
;
run;
data want;
do until(last.cust);
 set temp;
 by cust;
 if first.cust then first=dt;
end;
last=dt;
drop dt;
format first last date9.;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

One way:

proc summary data=temp nway;
   class cust;
   var dt;
   output out=want (drop=_: ) min=Fpd max=lpd;
run;

 

Ksharp
Super User

Assuming the data has been sorted .

 


data temp;
input cust dt :date9.;
format dt date9.;
datalines;
1 01apr2021
1 02apr2021
1 10apr2021
2 15apr2021
2 18apr2021
2 20apr2021
2 25apr2021
3 29apr2021
3 03may2021
4 04may2021
;
run;
data want;
do until(last.cust);
 set temp;
 by cust;
 if first.cust then first=dt;
end;
last=dt;
drop dt;
format first last date9.;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 440 views
  • 2 likes
  • 3 in conversation