msgbartop
List for SAS fans and programmer
msgbarbottom

05 4月 20 COVDI-19全球各国病例数弹道追踪图示

/** Trajectory GIF of covid 19 cases **/
/** 2020APR05 by sxlion **/
/** First on www.saslist.net **/

Filename data temp;
proc http
url = “https://covid.ourworldindata.org/data/ecdc/full_data.csv”
method = “GET”
out = data;
run;

PROC IMPORT OUT= WORK.ex0
FILE= data
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
GUESSINGROWS= max;
RUN;

data _null_;
set ex0 end=eof;
retain start end;
start = min(start,date);
end = max(end,date);
if eof then do;
call symput(‘start’, start);
call symput(‘end’, end);
end;
run;
%put &start. &end.;

proc sort data= ex0 out=ex0 ; by location date; run;
data ex (drop= c7 d7);
set ex0;
by location;
retain c7 d7 ;
if first.location then do; c7 =0 ; d7 = 0; count =0; end;
count+1 ;
last7c=lag7(new_cases);last7d=lag7(new_deaths);
if count gt 7 then do; c7 = sum(c7,new_cases,-last7c);
d7 = sum(d7,new_deaths,-last7d); end;
else do; c7 = sum(c7,new_cases);d7 = sum(d7,new_deaths); end;
if count ge 7 then do; new_cases_7 = ceil(c7/7); new_deaths_7 = ceil(d7/7);end;
else do; new_cases_7 = .; new_deaths_7 = .; end;
run;

/*–This program requires SAS 9.4 or later–*/
%macro GapMinder(data= , start=, end=);
%do date=&start %to &end ;

data _null_;
set &data.;
mag_y = min(max( 10**ceil(log10(total_cases+1)), 1000),100000);
mag_x = max( 10**ceil(log10(total_cases+1)), 1000);
call symput(‘max_axis_x’, mag_x);
call symput(‘max_axis_y’, mag_y);
call symput(‘day’,put(date,date9.));
call symput(‘total_cases’,put(total_cases,comma10.));
where date eq &date. and location eq “World” ;
run;

proc sgplot data=&data.;
title color = black h=1.4 “Trajectory of COVID-19 Confirmed Cases”;
title2 ” “;
title3 color=red h=1.2 font=”Arial” “Global Number” bold italic h=1.3 “&total_cases.”;

series x = total_cases y = new_cases_7 / curvelabel group =location
ARROWHEADSHAPE= barbed arrowheadpos=end arrowheadscale=1
LINEATTRS= (pattern=Solid thickness=1 color = blue )
SMOOTHCONNECT
CURVELABELATTRS=(Color=red Family=Arial Size=10 );
inset “&day.” / position=bottomright textattrs=(size=30 weight=bold color=lightgray);

xaxis LABEL=”Number of Total Cases” type = LOG logbase = 10 min=1 max= &max_axis_x.
LABELATTRS=(Color=gray Family=Arial Size=13 );
yaxis label= “New Cases(*ESC*){unicode ‘000a’x}(Moving Average Number of Last Week)” type = LOG logbase = 10 min=1 max= &max_axis_y.
LABELATTRS=(Color=gray Family=Arial Size=13 );

where date le &date. and location ne “World” and location ne “International” and total_cases gt 0 and new_cases_7 gt 0;
run;
%end;
%mend GapMinder;

/*–Set display labels only for a few countries–*/
data ex2;
set ex;
if (location in (‘Canada’,’World’,’China’,’South Korea’,’Turkey’,’Russia’,’India’,’Singapore’,’United States’,’Italy’,’Japan’));
/*’World’,’United States’, ‘India’, ‘China’,’South Korea’,’Singapore’,’Iran’,’Spain’,’Italy’,’France’,’Japan’)) ;*/
run;

/*–Create animation–*/
ods graphics / width=8in height=7in imagefmt=GIF border=no ANTIALIASMAX=4800;
options nodate nonumber
papersize=(‘8 in’, ‘7 in’)
printerpath=gif animation=start
animduration=0.25 animloop=no noanimoverlay;
ods printer file=’D:\Anim.gif’;

ods html select none ;
%GapMinder(data= ex2 ,start=&start., end=&end.);

ods html select all;

options printerpath=gif animation=stop;
ods printer close;

原创文章: ”COVDI-19全球各国病例数弹道追踪图示“,转载请注明: 转自SAS资源资讯列表

本文链接地址: http://saslist.net/archives/460

Pages: 1 2

Reader's Comments

  1.    

    Cool graph!
    could you share your code?

    Reply to this comment

Leave a Comment

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据