BookmarkSubscribeRSS Feed
arunvaibhav21
Calcite | Level 5

Hello All,

 

I need find out which CUSTOMER has given a "5" score immediately followed by a missing score (among the data shown above, it is C).

 

 

*Q10;
data feedback;
infile datalines missover;
input Customer $
	  Score 
	  Comment $30. ;
datalines;
A	3	The is no parking
A	5	The food is expensive
B	.	I like the food
C	5	It tastes good
C	.	 
C	3	I like the drink
D	4	The dessert is tasty
D	2	I don't like the services
;
run;
proc print data = feedback;
run;

proc sql;
select count(distinct Customer) into :n from feedback;
select distinct Customer into :cust1 - from feedback;
run;

%macro main();
%do i=1 %to &n.;
 data feedback_&&cust&i; set feedback;
 where Customer = "&&cust&i";
run;
%feedback_mn(cust=&&cust&i);
%end;
%mend;

%macro feedback_mn(cust=);
	data have;
	set feedback;
	where Customer = "&&cust&i";
 %if %length(Score)= 0 and lag1(Score) = 5 %then output;
 run;

 proc print data  = have;
 run;
%mend;
	
%main();

 

 

Any help is highly appreciated. please check the code, I am getting this error,

 

A character operand was found in the %EVAL function or %IF condition where a numeric operand
is required. The condition was: %length(Score)= 0 and lag1(Score) = 5
ERROR: The macro FEEDBACK_MN will stop executing.

3 REPLIES 3
Ksharp
Super User
data feedback;
infile datalines missover;
input Customer $
	  Score 
	  Comment $30. ;
datalines;
A	3	The is no parking
A	5	The food is expensive
B	.	I like the food
C	5	It tastes good
C	.	 
C	3	I like the drink
D	4	The dessert is tasty
D	2	I don't like the services
;
run;
data _null_;
 set feedback;
 if customer=lag(customer) and score=. and lag(score)=5 then put (_all_) (:);
run;
arunvaibhav21
Calcite | Level 5

Hello,

 

Thanks for the answer. But I dont see the output?

 

Thanks,

Arun

Ksharp
Super User

If you want a table .

 

data want;
 set feedback;
 if customer=lag(customer) and score=. and lag(score)=5 ;
run;

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