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


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1541 views
  • 0 likes
  • 3 in conversation