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

I'm new to SAS.

I have the following code but have no idea what the x1, x2, and x3 do in the second univariate.

They later get dropped.

 

/****************************************************************
* basic hour counts, beginning and ending ob times
****************************************************************/
proc univariate data=indat noprint;
by year mo gp hr;
var observationtime;
output out = sample
n = samplesizeqty
min = begindate
max = enddate;

 

/****************************************************************
* yearly month counts, beginning and ending ob times
****************************************************************/

proc univariate data=sample noprint;
by year mo;
var samplesizeqty begindate enddate;
output out = sample2
sum = samplesizeqty
min = x1 begindate
max = x2 x3 enddate;

 

data sample2;
set sample2;
by year mo;
gp = 1;
hr = 24;
drop x1-x3;
run;

 

proc sort data=sample2;
by year mo gp hr;

 

data sample;
merge sample sample2;
by year mo gp hr;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Not sure they are doing anything.   They are names you are using for statistics you are calculating.

In these two statements:

var samplesizeqty begindate enddate;
output
  out = sample2
  sum = samplesizeqty
  min = x1 begindate
  max = x2 x3 enddate
;

You are saying that X1 will be the minimum value of samplesizeqty .

X2 will be the maximum value of samplesizeqty.

X3 will be the maximum value of begindate.

 

I assume they are there because the programmer could not figure out how to set the names to use for the minumum value of begindate and the maximum value enddate without listing names for the variables that come before them in the VAR statement.

 

I know how to do it with PROC SUMMARY (aka PROC MEANS), but I am not sure if the syntax is the same for PROC UNIVARIATE, you could try.

 

But since you are not calculating any statistics that need PROC UNIVARIATE you can just use PROC MEANS (aka PROC SUMMARY) instead.

proc summary data=sample;
  by year mo;
  var samplesizeqty begindate enddate;
  output
    out = sample2
    sum(samplesizeqty) = samplesizeqty
    min(begindate) = begindate
    max(enddate) = enddate
  ;
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Not sure they are doing anything.   They are names you are using for statistics you are calculating.

In these two statements:

var samplesizeqty begindate enddate;
output
  out = sample2
  sum = samplesizeqty
  min = x1 begindate
  max = x2 x3 enddate
;

You are saying that X1 will be the minimum value of samplesizeqty .

X2 will be the maximum value of samplesizeqty.

X3 will be the maximum value of begindate.

 

I assume they are there because the programmer could not figure out how to set the names to use for the minumum value of begindate and the maximum value enddate without listing names for the variables that come before them in the VAR statement.

 

I know how to do it with PROC SUMMARY (aka PROC MEANS), but I am not sure if the syntax is the same for PROC UNIVARIATE, you could try.

 

But since you are not calculating any statistics that need PROC UNIVARIATE you can just use PROC MEANS (aka PROC SUMMARY) instead.

proc summary data=sample;
  by year mo;
  var samplesizeqty begindate enddate;
  output
    out = sample2
    sum(samplesizeqty) = samplesizeqty
    min(begindate) = begindate
    max(enddate) = enddate
  ;
run;

 

Bob9
Calcite | Level 5

Thank you!  What you said makes sense to me.  I really appreciate the help.  There are several more of these and now I believe that I understand and that feels good.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 636 views
  • 2 likes
  • 2 in conversation