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.
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;
Hello,
Thanks for the answer. But I dont see the output?
Thanks,
Arun
If you want a table .
data want;
set feedback;
if customer=lag(customer) and score=. and lag(score)=5 ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.