Solved
New Contributor
Posts: 2

# Understanding the code below - Newbie

I am a newbie with SAS. I need help in understanding the code below. Thank you!

``````PROC SUMMARY DATA=testdat.Input

CLASS CUSIP Date;

VAR PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ;``````

Accepted Solutions
Solution
‎01-22-2018 11:59 PM
Super User
Posts: 23,323

## Re: Understanding the code below - Newbie

The code is missing a semi colon on the first line and missing a RUN; at the end. See the comments in the code below that helps to explain what it's doing. If you have further questions please post back.

``````PROC SUMMARY DATA=testdat.Input; *specify to run a summary procedure on the data set INPUT;

CLASS CUSIP Date; *Group the summaries by CUSIP and DATE;

VAR PRCE; *Summarize the variable PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ; *output the results to a dataset called range_all, the statistics being calculated are the RANGE and N(count). The RANGE is stored in a variable called range_all and the count is stored in countall;Run;``````

Vinz867 wrote:

I am a newbie with SAS. I need help in understanding the code below. Thank you!

``````PROC SUMMARY DATA=testdat.Input

CLASS CUSIP Date;

VAR PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ;``````

All Replies
Solution
‎01-22-2018 11:59 PM
Super User
Posts: 23,323

## Re: Understanding the code below - Newbie

The code is missing a semi colon on the first line and missing a RUN; at the end. See the comments in the code below that helps to explain what it's doing. If you have further questions please post back.

``````PROC SUMMARY DATA=testdat.Input; *specify to run a summary procedure on the data set INPUT;

CLASS CUSIP Date; *Group the summaries by CUSIP and DATE;

VAR PRCE; *Summarize the variable PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ; *output the results to a dataset called range_all, the statistics being calculated are the RANGE and N(count). The RANGE is stored in a variable called range_all and the count is stored in countall;Run;``````

Vinz867 wrote:

I am a newbie with SAS. I need help in understanding the code below. Thank you!

``````PROC SUMMARY DATA=testdat.Input

CLASS CUSIP Date;

VAR PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ;``````

New Contributor
Posts: 2

## Re: Understanding the code below - Newbie

When you say summarize the variance PRCE, is it summing up the prices based on the CUSIP and date?

Reeza wrote:

The code is missing a semi colon on the first line and missing a RUN; at the end. See the comments in the code below that helps to explain what it's doing. If you have further questions please post back.

``````PROC SUMMARY DATA=testdat.Input; *specify to run a summary procedure on the data set INPUT;

CLASS CUSIP Date; *Group the summaries by CUSIP and DATE;

VAR PRCE; *Summarize the variable PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ; *output the results to a dataset called range_all, the statistics being calculated are the RANGE and N(count). The RANGE is stored in a variable called range_all and the count is stored in countall;Run;``````

Vinz867 wrote:

I am a newbie with SAS. I need help in understanding the code below. Thank you!

``````PROC SUMMARY DATA=testdat.Input

CLASS CUSIP Date;

VAR PRCE;

OUTPUT OUT=testdat.range_all range=range_all n=countall ;``````

Super User
Posts: 23,323

## Re: Understanding the code below - Newbie

Vinz867 wrote:

When you say summarize the variance PRCE, is it summing up the prices based on the CUSIP and date?

Yes, it calculates the N and Range of the variable PRCE, for each unique combination of CUSIP and DATE.

Super User
Posts: 7,938

## Re: Understanding the code below - Newbie

[ Edited ]

Since you did not include the NWAY option on your PROC SUMMARY statement this code will produce multiple sets of outputs in the same output dataset.  You can distinguish them by looking at the automatic variable _TYPE_ that it creates.

.

In your example you have two CLASS variables so _TYPE_ will have four possible values that result from two binary flags.

_TYPE_=00 will have one observation with the summary for all of the input data.

_TYPE_=3 ( or '11'b ) will have one observation for each distinct combination of the two class variables.

_TYPE_=2 and 1 ('10'b and '01'b) will have the summary for each distinct value of just one of the two class variables considered independently.

☑ This topic is solved.