- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-02-2009 03:06 PM
(5087 views)
I typically write this type of code using PROC SQL statements but I'm trying to see if there are other ways of doing it using more inherent SAS code.
I have a dataset that I want to summarize that has multiple recods per the class column that I'll be summarizing by. What I would like to do is conditionally summarize the data (sales) based on another column in the set.
Here is what I have:
classVar: what I will summarize by (the CLASS statement)
numVar1, numVar2 numVar3: the columns for the VAR statement
txtVar1: the column that I want to conditionally summarize by
This works to get totals (I know there are other nuances of writing the code):
proc summary data=mydata;
var numVar1 numVar2 numVar3;
class classVar;
types classVar; /* do not include the "total" row */
output out=myoutput
sum(numVar1)=smVar1
sum(numVar2)=smVar2
sum(numVar3)=smVar3
;
run;
Does anyone know if you can conditionally sum .. for example if txtVAr1 has two different options ("Yes" and "No" for example), can proc summary actually generate 6 output columns instead of just the 3 as seen above?
I've google'd this to no result so if anyone has any insight, it would be greatly appreciated. So far I'm coming to the conclusion that it's not possible and I just need to go back to PROC SQL and write the scripts myself.
Thanks!
Daniel
I have a dataset that I want to summarize that has multiple recods per the class column that I'll be summarizing by. What I would like to do is conditionally summarize the data (sales) based on another column in the set.
Here is what I have:
classVar: what I will summarize by (the CLASS statement)
numVar1, numVar2 numVar3: the columns for the VAR statement
txtVar1: the column that I want to conditionally summarize by
This works to get totals (I know there are other nuances of writing the code):
proc summary data=mydata;
var numVar1 numVar2 numVar3;
class classVar;
types classVar; /* do not include the "total" row */
output out=myoutput
sum(numVar1)=smVar1
sum(numVar2)=smVar2
sum(numVar3)=smVar3
;
run;
Does anyone know if you can conditionally sum .. for example if txtVAr1 has two different options ("Yes" and "No" for example), can proc summary actually generate 6 output columns instead of just the 3 as seen above?
I've google'd this to no result so if anyone has any insight, it would be greatly appreciated. So far I'm coming to the conclusion that it's not possible and I just need to go back to PROC SQL and write the scripts myself.
Thanks!
Daniel
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about:
1) create additional "count" columns based on some variable condition, or
2) split your file into two files, perform two PROC SUMMARY executions under difference rqmts and then bring the two files back together (and maybe requiring a third PROC SUMMARY).
Scott Barry
SBBWorks, Inc.
1) create additional "count" columns based on some variable condition, or
2) split your file into two files, perform two PROC SUMMARY executions under difference rqmts and then bring the two files back together (and maybe requiring a third PROC SUMMARY).
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why don't you request[pre]class classVar txtVAr1 ;[/pre]to get the 6 values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
> Why don't you request[pre]class classVar txtVAr1
> ;[/pre]to get the 6 values?
If you want only the cross product of the class variables but not the idividual summaries of each class variable use the NWAY option on the proc statement with this approach.
> ;[/pre]to get the 6 values?
If you want only the cross product of the class variables but not the idividual summaries of each class variable use the NWAY option on the proc statement with this approach.