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

I have few questions for the code below and would like to get some help. My understanding is it did some thing on &dsnn._2 and output to &dsnn._3 but I don't understand

1. The d_member_id, date1, and indexdt are columns. What does class do and get here?

2. What is the variable name for day1 - day&post_days.? what does it do here?

3. This code "(where=(d_member_id ne .) drop=_:) max=;" 

  a. (d_member_id ne .) means d_member_id not = blank? The d_member_id shouldn't have blank.

  b. drop what?

  c. max what? if max a column, what is the group by?

 

proc means data=&dsnn._2 noprint nway;
class d_member_id date1 indexdt;
var day1 - day&post_days.;
output out=&dsnn._3(where=(d_member_id ne .) drop=_:) max=;

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Dee2
Obsidian | Level 7

Thanks.

2. What is the variable name for day1 - day&post_days.? what does it do here? This is a "SAS Variable List" if POST_DAYS is 7 then DAY1-DAY7

 Day1 minus Day7?

a. (d_member_id ne .) means d_member_id not = blank? The d_member_id shouldn't have blank. Filter the output data.  Without MISSING options there should be not missing class levels.  Filter d_member_id not = blank? (ne .)?

Thanks again.

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

@Dee2 wrote:

I have few questions for the code below and would like to get some help. My understanding is it did some thing on &dsnn._2 and output to &dsnn._3 but I don't understand

1. The d_member_id, date1, and indexdt are columns. What does class do and get here? Class defines the groups for the summary.

2. What is the variable name for day1 - day&post_days.? what does it do here? This is a "SAS Variable List" if POST_DAYS is 7 then DAY1-DAY7.

3. This code "(where=(d_member_id ne .) drop=_:) max=;" 

  a. (d_member_id ne .) means d_member_id not = blank? The d_member_id shouldn't have blank. Filter the output data.  Without MISSING options there should be not missing class levels.

  b. drop what? Another "SAS Variable List" drop variables that begin with "_" (i.e. _TYPE_ _FREQ_)

  c. max what? if max a column, what is the group by? MAX of all variables in VAR statement and name the MAX same as VAR

 

proc means data=&dsnn._2 noprint nway;
class d_member_id date1 indexdt;
var day1 - day&post_days.;
output out=&dsnn._3(where=(d_member_id ne .) drop=_:) max=;

 

Thanks.


 

Dee2
Obsidian | Level 7

Thanks.

2. What is the variable name for day1 - day&post_days.? what does it do here? This is a "SAS Variable List" if POST_DAYS is 7 then DAY1-DAY7

 Day1 minus Day7?

a. (d_member_id ne .) means d_member_id not = blank? The d_member_id shouldn't have blank. Filter the output data.  Without MISSING options there should be not missing class levels.  Filter d_member_id not = blank? (ne .)?

Thanks again.

data_null__
Jade | Level 19

You're welcome Obsidian. 
@Dee2 wrote:

Thanks Jade.

2. What is the variable name for day1 - day&post_days.? what does it do here? This is a "SAS Variable List" if POST_DAYS is 7 then DAY1-DAY7

 Day1 minus Day7? For a "SAS Variable List" the - (minus sign) indicates a list of enumerated variables DAY1 DAY2 DAY3 ... DAY7

a. (d_member_id ne .) means d_member_id not = blank? The d_member_id shouldn't have blank. Filter the output data.  Without MISSING options there should be not missing class levels.  Filter d_member_id not = blank? (ne .)?  also NOT missing(d_member_id)

Thanks.


 

 

 

ballardw
Super User

And addition to @data_null__ response for 3.C

 

If you request only a single statistic for a variable in an output data set created with the OUTPUT statement, such as Max= then your variable in the output data set with the name on the VAR statement holds the statistic value.

If you request multiple statistics then you need to provide names for some of the variables.

You can test this with the following bits of code:

proc means data=sashelp.class noprint nway;
   class sex;
   var height weight;
   output out=wrong  max= min= std=
   ;
run;

Which generates warnings in the log about variables already exist in the output data set. Since MAX is listed first that is the only value in the output.

The following shows how to rename the statistics for each variable with specific names

proc means data=sashelp.class noprint nway;
   class sex;
   var height weight;
   output out=wrong  max= min(height weight)=minh minw std(height weight)=hstd wstd
   ;
run;

The name of the variable on the VAR statement goes in () after the statistic and the name(s) of the output variables follow the = . The number of variables and new names need to match. Order is critical.

Or you can let SAS help you out with (mostly) predictable names:

proc means data=sashelp.class noprint nway;
   class sex;
   var height weight;
   output out=wrong  max= min= std= /autoname
   ;
run;

The autoname option will name the output variables by appending the statistic to the variable name.

 

One of the things you didn't ask about but can be quite helpful was the NWAY option. If you do not include NWAY then you will get combinations of the class variables. I have found this quite helpful because I get the summaries of literally dozens of likely combinations of variables. The _type_ variable in the output indicates which combination a set of records represents. So with one pass through the data I had a data set that contained in on project summaries at:

Statewide

Geographic region

County

School District

School type (public/private)

School

Grade

 

Geographic region by school district

Geographic region by school type

Geographic region by grade

Geographic region by school type by grade

(and a LOT more combinations).

This is useful because you can use combinations of WHERE clauses to select records and/or BY variables to Print or other report procedure. I created around 4,000 pages of custom reports different levels of management using ONE output data set (and some additional code to make each type nice in appearance)

 

 

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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