BookmarkSubscribeRSS Feed
Jazz_SAS
Calcite | Level 5
Hello People. I'm learner in SAS.

I have a simple query in access:

SELECT Tbl.Location, Tbl.Jobcode, Count(Tbl.EmpId), Sum(Tbl.Salary)
FROM Tbl
GROUP BY Tbl.Location, Tbl.Jobcode;


I need to display the same results in SAS. The dataset is created.

The code i'm trying to write is as follows:

PROC SORT DATA = msdq.crew OUT=work.Tbl;
BY Location Jobcode;
RUN;

PROC PRINT DATA = Tbl;
ID Location Jobcode;
BY Location Jobcode;
VAR Salary;
SUM Salary;
RUN;


I need to write Count(EmpId) and Sum(Salary)

And also the above code does not group the two variables; it creates a Sub-total and a grand total.

How to group. Help me out plz ?
5 REPLIES 5
Patrick
Opal | Level 21
Why don't you just use this already tested SQL code in SAS?

Proc sql;
SELECT Tbl.Location, Tbl.Jobcode, Count(Tbl.EmpId), Sum(Tbl.Salary)
FROM Tbl
GROUP BY Tbl.Location, Tbl.Jobcode;
quit;
Ksharp
Super User
proc report or proc tabulate would be a better choice.
and Cynthia@sas.com can do it better.hehe.
This is just an example.

[pre]
proc tabulate data=sashelp.class;
class sex name;
var weight height;
table sex*name,weight*n height*sum;
run;
[/pre]


Ksharp
Cynthia_sas
SAS Super FREQ
Hi:
Ksharp has posted one possible solution. Another solution (if you want a "grouped" report (such as without name), would be to take her TABULATE code and remove the "*name" from the TABLE statement.

Otherwise, you can also achieve a grouped or summary report with PROC REPORT, as well, consider the program below. In this program, the variables SEX and AGE are group variables and so the "detailed" observations will collapse into groups of unique ages within each sex value. Then the Weight variable is used to get the N statistic to count the observations in each SEX/AGE group and the HEIGHT variable is used to get the SUM of HEIGHTS (not very meaningful, but it is only meant to show the use of the SUM statistic).

cynthia
[pre]
proc report data=sashelp.class nowd;
column sex age weight height;
define sex / group;
define age / group;
define height / sum;
define weight / n 'Count';
rbreak after / summarize;
run;
[/pre]
Ksharp
Super User
Hi. Cynthia. I am boy ,thirty years old.hehe.
Cynthia_sas
SAS Super FREQ
Sorry for the misunderstanding.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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