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;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 4208 views
  • 1 like
  • 2 in conversation