BookmarkSubscribeRSS Feed
woo
Barite | Level 11 woo
Barite | Level 11

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;

4 REPLIES 4
ballardw
Super User

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?

woo
Barite | Level 11 woo
Barite | Level 11

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

Astounding
PROC Star

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.

LinusH
Tourmaline | Level 20

Why?

Data never sleeps

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 1777 views
  • 0 likes
  • 4 in conversation