Classify data

Reply
Contributor
Posts: 41

Classify data

data orders;
input CustomerID$1-3 OrderDate DATE7. Model $13-24 Quantity ;
datalines;
287 15OCT03 Delta Breeze 15
287 15OCT03 Santa Ana     15
274 16OCT03 Jet Stream       1
174 17OCT03 Santa Ana      20
174 17OCT03 Nor' easter      5
174 17OCT03 Scirocco         1
347 18OCT03 Mistral           1 
287 21OCT03 Delta Breeze   30
287 21OCT03 Santa Ana       25
;
run;
proc print data = orders NOOBS;
where customerID ='&customerclass';
format quantity ;
title 'current models of &customerclass bicycles';
run;
%MACRO PRINTIT;
proc print data =orders NOOBS;
title 'current models';
var CustomerID OrderDate Model Quantity;

format quantity ;
run;
%MEND printit;
%printit

proc sort data=models;
by quantity;
%printit

1. I want to classify the same customers' ID into a group and then plus their quantity together what command I can use?

2. How to controll the quantity in increasing order or decreasing order ?

Thanks.

Super User
Posts: 18,997

Re: Classify data

1. Proc means or proc Summary or proc univariate

2. If you want to sort descending add the key word DESCENDING before the variable in PROC SORT. 

Super Contributor
Posts: 259

Re: Classify data

proc sort data=orders;
by CustomerID;
run;


proc summary data=orders ;
by CustomerId;
var quantity;
output out=want mean=mean_qty;
run;

proc sort data =want ;
by mean_qty;
run;
Super User
Posts: 5,352

Re: Classify data

There are a few items to clean up first:

 

  • Macro variables in single quotes do not resolve.  You need to switch to double quotes if you want SAS to properly interpret "&customerclass"
  • There is no reason to put your PROC PRINT into a macro.  It is normal in SAS to create a data set then print it without using macro language.  You may need a macro earlier than that, for your DATA step to refer to a macro variable.  But you don't need a macro to print an existing data set.
  • You can't sort the data set MODELS because there is no such data set.  The only data set you would want to sort here is ORDERS.

Once those issues are cleared up, you can look at how PROC SORT can change the order of the observations.  At that point, you can also consider whether you want to group all customers, or whether you want to process only a single CustomerID.

Contributor
Posts: 41

Re: Classify data

How to rectify the program to match point 1 and 2?
Super User
Posts: 5,352

Re: Classify data

For point 1, change all single quotes to double quotes.

 

For point 2, you have to decide on the result you want.  Do you actually want to print the data set twice (once before sorting, and once after sorting)?  If you only want to print it once, when should it print (again, before vs. after sorting)?

Ask a Question
Discussion stats
  • 5 replies
  • 266 views
  • 4 likes
  • 4 in conversation