BookmarkSubscribeRSS Feed
Guptashwe
Calcite | Level 5

data t1;
input cinfno carte$;
datalines;
1 caba
1 cb
2 cb
3 caba
4 cb
4 caba

5 caba
;
run;

 

Using data steps write a code to display the number of customers having 

carte: CB

Carte: caba

carte : both

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data t1;
input cinfno carte$;
datalines;
1 caba
1 cb
2 cb
3 caba
4 cb
4 caba
5 caba
;
run;    
/*no of customers having both*/
data w1;
set t1 end=lr;
by cinfno;
if not(first.cinfno and last.cinfno) then f=1;
if last.cinfno and f then no_of_customers_both+1;
if lr;
keep no_of_customers_both;
run;

proc sort data =t1 out=t;
by carte;
run;
data w2;
set t end=lr;
by carte;
if first.carte then numberofcustomers=1;
else  numberofcustomers+1;
if last.carte;
run;
Reeza
Super User

Hi @Guptashwe 

Note that I've updated the subject line of your question to be more descriptive. Please use a more descriptive subject line in the future. This is to allow other future users to search for a topic and find the relevant answers more easily. 

 


@Guptashwe wrote:

data t1;
input cinfno carte$;
datalines;
1 caba
1 cb
2 cb
3 caba
4 cb
4 caba

5 caba
;
run;

 

Using data steps write a code to display the number of customers having 

carte: CB

Carte: caba

carte : both


 

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