BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jjsingh04
Obsidian | Level 7

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. 

Our lives are enriched by the people around us.
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
jjsingh04
Obsidian | Level 7

@PaigeMiller 

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. 

Our lives are enriched by the people around us.
Astounding
PROC Star

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.

jjsingh04
Obsidian | Level 7

@Astounding 

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. 

Our lives are enriched by the people around us.
Astounding
PROC Star

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.

jjsingh04
Obsidian | Level 7

@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. 

Our lives are enriched by the people around us.

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!

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
  • 6 replies
  • 644 views
  • 4 likes
  • 3 in conversation