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