Is there some easier method than this:
proc means data=crspy2 noprint nway; class csp8 cryr; var abrm; output out=crspy3(drop=_:) skewness=retskew; run; proc sql; create table crspix (drop=abrm oneplus) as select crspy2.*, crspy3.* from crspy2, crspy3 where crspy2.csp8=crspy3.csp8 ne "." and crspy2.cryr=crspy3.cryr order by crspy2.csp8, crspy3.cryr; quit;
to achieve what this does? I had to add on the Proc Sql because the output from the Proc Means (i.e. crspy3) only contains the variables csp8, cryr, and retskew. That does make sense to me, considering the presumed purpose of Proc Means. I'm just wondering if I can adjust the Proc Means code somehow so that the output would also have the (original) retadj and retsd variables. (It's okay if the original abrm and oneplus variables still go though, as I soon get rid of them anyway.) (FYI: Note that the (drop=_:) code only gets rid of the _TYPE_ and _FREQ_ variables, which is fine.)
Thanks,
J.J.
It depends on what you consider easier. Here's a recommendation.
SQL is sorting the data. So you could simplify the program if you were to sort it yourself:
proc sort data=crpsy2;
by csp8 cryr;
run;
This allows change to the rest of the steps, which could become:
proc means data=crspy2 noprint;
by csp8 cryr;
var abrm;
output out=crspy3(drop=_:) skewness=retskew;
run;
data crspix (drop=abm oneplus);
merge crspy2 crspy3;
by csp8 cryr;
run;
I did remove your reference to missing values ... you could always add it back into the DATA step if you need to delete some observations.
Sorted data removes the need for a CLASS statement, letting you use a BY statement instead. That removes the need for the NWAY option.
Sorted data allows you to use a simple MERGE in a DATA step, instead of SQL, to combine your data sets.
I'm just wondering if I can adjust the Proc Means code somehow so that the output would also have the (original) retadj and retsd variables.
We don't know what your data looks like, we don't know anything about RETADJ and RETSD variables, and so we can't know what this actually means. Please show us a portion of your data, by creating working SAS data step code typing it in yourself, or by following these instructions.
Thanks for your advice. Sorry I was short on details in my post. It was close to 3 am when I posted the question and I was exhausted after a long day. My variables are all numbers except csp8 which is alphanumeric. Most numbers have decimals, except for cryr, which is an integer. I'll try to explicate better next time.
J.J.
It depends on what you consider easier. Here's a recommendation.
SQL is sorting the data. So you could simplify the program if you were to sort it yourself:
proc sort data=crpsy2;
by csp8 cryr;
run;
This allows change to the rest of the steps, which could become:
proc means data=crspy2 noprint;
by csp8 cryr;
var abrm;
output out=crspy3(drop=_:) skewness=retskew;
run;
data crspix (drop=abm oneplus);
merge crspy2 crspy3;
by csp8 cryr;
run;
I did remove your reference to missing values ... you could always add it back into the DATA step if you need to delete some observations.
Sorted data removes the need for a CLASS statement, letting you use a BY statement instead. That removes the need for the NWAY option.
Sorted data allows you to use a simple MERGE in a DATA step, instead of SQL, to combine your data sets.
Thanks for your help. I should've mentioned that my data had already been sorted but from what I understand of CLASS, it allows you to not have to sort the data first--unlike BY, right? I'm not too familiar with MERGE--thanks for the tip. I'll look into it further.
J.J.
You're correct on all counts. If the data set is already sorted, you don't need to sort it again. CLASS does avoid the need for having sorted data. And if your data is already in order, you can use a BY statement without sorting again.
@Astounding Thanks for clarifying. I thought about your solution after I posted that subsequent question and I like it very much. I guess I've just gotten so used to using Proc Sql that I didn't realize that there are much more succinct alternative ways of coding out there like Data Step Merge. Thank you for telling me about Data Step Merge. I will definitely be using it when I can hereon.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.