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

Hi Everyone,

 

I am trying to summaries data contained in sashelp.class using PROC SQL to a report similar (column headers might be different but information contained should match) to the below output generated from PROC REPORT:

 

Screenshot 2018-11-04 at 20.36.31.png

 

The script I have written is this:

proc sql;
select 
age,
case when Sex='F' then sum(Weight) else . end as Weight_Femal,
case when Sex='M' then sum(weight) else . end as Weight_Male from sashelp.class group by 1; quit;

However, this generates the error message: Screenshot 2018-11-04 at 20.38.54.png

 

I know what the error is, but in this case i dont know how to correct it. Can anyone help please?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

proc sql;
  select age
        ,sum(case when Sex='F' then Weight else . end) as Weight_F
        ,sum(case when Sex='M' then Weight else . end) as Weight_M 
  from sashelp.class
  group by 1;
quit;

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

proc sql;
  select age
        ,sum(case when Sex='F' then Weight else . end) as Weight_F
        ,sum(case when Sex='M' then Weight else . end) as Weight_M 
  from sashelp.class
  group by 1;
quit;

 

ChrisNZ
Tourmaline | Level 20

You cam also write this as:

proc sql;
  select AGE
        ,sum((SEX='F') * WEIGHT) as WEIGHT_F
        ,sum((SEX='M') * WEIGHT) as WEIGHT_M
  from SASHELP.CLASS
  group by 1;
quit;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 4003 views
  • 1 like
  • 2 in conversation