BookmarkSubscribeRSS Feed
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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