hello friends - if you can tell me how can i write below proc sql query in data step? thank you
PROC SQL;
CREATE TABLE WORK.Query2_for_TEST3 AS SELECT DISTINCT TEST3.date,
TEST3.Item_number,
(COUNT(TEST3.found)) AS COUNT_OF_found
FROM WORK.TEST3 AS TEST3
GROUP BY TEST3.Item_number
ORDER BY TEST3.Item_number;
QUIT;
It would better to show start data and desired end.
DATA step probably wouldn't be the best as it has not equivalent of GROUP BY or DISTINCT.
I would try if found is numeric:
proc summary data = work.test3 nway;
class Item_number date;
var found;
output out=qork.query2_for_test3 (drop= _type_ _freq_) n= count_of_found;
run;
Or did you need group by Item_number, date for your original query?
so have this: date (in date format) (item_number and found both are numeric)
date item_number found
01oct14 123456 1
02oct14 123456 2
01oct14 789101 1
02oct14 789101 2
03oct14 789101 3
04oct14 789101 4
01oct14 111111 1
01oct14 222222 1
02oct14 222222 2
03oct14 222222 3
and want this
date item_number count_of_found
01oct14 123456 2
02oct14 123456 2
01oct14 789101 4
02oct14 789101 4
03oct14 789101 4
04oct14 789101 4
01oct14 111111 1
01oct14 222222 3
02oct14 222222 3
03oct14 222222 3
A DATA step might look like this:
data want;
count_of_found=0;
do until (last.item_number);
set have;
by item_number notsorted;
count_of_found + 1;
end;
do until (last.item_number);
set have;
by item_number notsorted;
output;
end;
run;
Optionally, you could drop FOUND from the final data set.
Good luck.
Why?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.