BookmarkSubscribeRSS Feed
Feksan
Fluorite | Level 6

Hi, I have created a table that gives me two variables as you can see:

PROC SUMMARY data=mylib_d3.covid_data mean print;
VAR new_cases new_deaths;
BY continent date;
output out=mylib_d3.mean_cas_deces mean=mean_nouveaux_cas mean_nouveaux_deces;
RUN;

 

Then, I want to get for each of the columns just created the minimum and the maximum with this code but it's giving me the same number for both minimums and boths maximums:

PROC SUMMARY data=mylib_d3.MOYENNE_CAS_DECES min max print;
VAR moyenne_nouveaux_cas moyenne_nouveaux_deces;
BY continent date;
output out=mylib_d3.min_max_cas_deces min=min_nouveaux_cas min_nouveaux_deces
max=max_nouveaux_cas max_nouveaux_deces;
RUN;

 

What could be wrong?

9 REPLIES 9
Kurt_Bremser
Super User

If you use the output of the first SUMMARY as input for the second, then you only have one observation per group. It is then obvious that min=max.

 

If that is not the case, run those two steps in one submit and post the complete log of this by copy/pasting into a window opened with the </> button.

Feksan
Fluorite | Level 6

Let's say I have this data set and I want to get the minimum and maximum average of new cases and new deaths by continent and by date.

What could be the code?

PaigeMiller
Diamond | Level 26

Minor variations of your PROC SUMMARY code above will work. Give it a try. If you get stuck, show us the code you have tried so far.

 

Please do not provide data as attachments. The proper method to provide data is to follow these instructions.

--
Paige Miller
Feksan
Fluorite | Level 6

I have tried this:

 

PROC SORT data=mylib_d3.covid_data;
BY continent date;
RUN;
PROC SUMMARY data=mylib_d3.covid_data mean print;
VAR new_cases new_deaths;
BY continent date;
output out=mylib_d3.moyenne_cases_deaths mean=moyenne_new_cas moyenne_new_deces;
RUN;

 


PROC SUMMARY data=mylib_d3.MOYENNE_CAS_DECES min max print;
VAR moyenne_new_cas moyenne_new_deaths;
BY continent;
output out=mylib_d3.min_max_cas_deces min=min_new_cases min_new_deaths
max=max_new_cas max_new_deces;
RUN;

PaigeMiller
Diamond | Level 26

Yes, you have posted that code already and @Kurt_Bremser explained what the mistake was, but it doesn't seem as if you have fixed the mistake that he pointed out.

--
Paige Miller
Kurt_Bremser
Super User

Your CSV file does not contain a column "continent", so it is useless, even if I wrote code to read it.

Please provide example data in a data step with datalines, use the "little running man" button to open a window for copy/pasting the code into.

Next, post the code you run off this particular dataset; also make sure that data created in step1 is the one used in step 2, and so on.

 

Feksan
Fluorite | Level 6

This is from my log:


1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='MATH30602.A2020_Devoir3_11286690.sas';
4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTPATHHOST='';
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='C:\Users\admin\Desktop\Logiciels statistiques\Devoir individuel
8 ! 3\MATH30602.A2020_Devoir3_11286690.sas';
9 %LET _SASPROGRAMFILEHOST='WILLY-CLAUDE-KA';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 %macro HTML5AccessibleGraphSupported;
15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
16 %mend;
17 FILENAME EGHTML TEMP;
18 ODS HTML5(ID=EGHTML) FILE=EGHTML
19 OPTIONS(BITMAP_MODE='INLINE')
20 %HTML5AccessibleGraphSupported
21 ENCODING='utf-8'
22 STYLE=HtmlBlue
23 NOGTITLE
24 NOGFOOTNOTE
25 GPATH=&sasworklocation
26 ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 PROC SORT data=mylib_d3.covid_data;
29 BY continent date;
30 RUN;

NOTE: Input data set is already sorted, no sorting done.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

31 PROC SUMMARY data=mylib_d3.covid_data mean print;
32 VAR nouveaux_cas nouveaux_deces;
33 BY continent date;
34 output out=mylib_d3.moyenne_cas_deces mean=moyenne_nouveaux_cas moyenne_nouveaux_deces;
35 RUN;

NOTE: There were 38358 observations read from the data set MYLIB_D3.COVID_DATA.
NOTE: The data set MYLIB_D3.MOYENNE_CAS_DECES has 1416 observations and 6 variables.
NOTE: PROCEDURE SUMMARY used (Total process time):
real time 22.74 seconds
cpu time 22.68 seconds

36 PROC SUMMARY data=mylib_d3.MOYENNE_CAS_DECES min max print;
37 VAR moyenne_nouveaux_cas moyenne_nouveaux_deces date;
38 BY continent date;
39 output out=mylib_d3.min_max_cas_deces min=min_nouveaux_cas min_nouveaux_deces
40 max=max_nouveaux_cas max_nouveaux_deces;
41 RUN;
2 The SAS System 19:13 Tuesday, December 1, 2020


NOTE: There were 1416 observations read from the data set MYLIB_D3.MOYENNE_CAS_DECES.
NOTE: The data set MYLIB_D3.MIN_MAX_CAS_DECES has 1416 observations and 8 variables.
NOTE: PROCEDURE SUMMARY used (Total process time):
real time 43.90 seconds
cpu time 37.34 seconds

42
43 %LET _CLIENTTASKLABEL=;
44 %LET _CLIENTPROCESSFLOWNAME=;
45 %LET _CLIENTPROJECTPATH=;
46 %LET _CLIENTPROJECTPATHHOST=;
47 %LET _CLIENTPROJECTNAME=;
48 %LET _SASPROGRAMFILE=;
49 %LET _SASPROGRAMFILEHOST=;
50
51 ;*';*";*/;quit;run;
52 ODS _ALL_ CLOSE;
53
54
55 QUIT; RUN;
56

Kurt_Bremser
Super User

As I said, after the first SUMMARY, mylib_d3.MOYENNE_CAS_DECES will have only one observation per continent and date, and so the MAX and MIN for the same BY or CLASS wiil by definition be equal. If you want to get meaningful values, calculate the MIN and MAX in the same step where you calculate the MEAN.

Tom
Super User Tom
Super User

So this step:

PROC SUMMARY data=mylib_d3.covid_data mean print;
  BY continent date;
  VAR new_cases new_deaths;
  output out=mylib_d3.mean_cas_deces mean=mean_nouveaux_cas mean_nouveaux_deces;
RUN;

Will create one observation per CONTINENT DATE if you want to find the MIN/MAX of those MEAN values you will need to eliminate one of the BY variables. 

For example if you eliminate DATE from the BY statement you will get the MIN and MAX of the daily means per CONTINENT:

PROC SUMMARY data=mylib_d3.MOYENNE_CAS_DECES min max print;
  BY continent ;
  VAR moyenne_nouveaux_cas moyenne_nouveaux_deces;
  output out=mylib_d3.min_max_cas_deces
    min=min_nouveaux_cas min_nouveaux_deces
    max=max_nouveaux_cas max_nouveaux_deces
  ;
RUN;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 1350 views
  • 1 like
  • 4 in conversation