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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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