BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Neil_C
Calcite | Level 5

Hello,

I need a quick help. I have the following data:

ID Group      Price

1      x            10

1      y            9

2      x           3

2      x           4

2      z            7

...

...

I wanted a subtotal of price by group and then by ID but would like to create a dataset out of parent data, without displaying using proc print (which took a long time).

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

proc summary data=have nway;

     class group id;

     var price;

     output out=want (drop=_type_ _freq_) sum=;

run;

If you want to know how many records were in each combination of group and id remove _freq_ in the code above. That is what that variable holds.

View solution in original post

3 REPLIES 3
ballardw
Super User

proc summary data=have nway;

     class group id;

     var price;

     output out=want (drop=_type_ _freq_) sum=;

run;

If you want to know how many records were in each combination of group and id remove _freq_ in the code above. That is what that variable holds.

Neil_C
Calcite | Level 5

Thank you for the quick help. Is there anyway I can do the same thing using first. and last. processing?

PGStats
Opal | Level 21

There is a simple way :

data have;

input ID Group $     Price;

datalines;

1      x            10

1      y            9

2      x           3

2      x           4

2      z            7

;

proc sort data=have; by group id; run;

data want;

do until(last.id);

    set have; by group id;

    priceSum = sum(priceSum, price);

    end;

keep group id  priceSum;

run;

PG

PG

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 950 views
  • 3 likes
  • 3 in conversation