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?
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.
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?
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.
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;
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.
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.
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
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.
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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.