PROC IMPORT OUT= WORK.USReps DATAFILE= "C:\\USReps.csv" DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; RUN; proc iml; /* 1. Read data */ use USReps where(name^="District of Columbia"); read all var "Name"; read all var _NUM_ into Count[c=YearName]; close USReps; Year = num(substr(YearName, 6, 4)); /* convert to years */ /* 2. First row is total number of US reps. Scale other rows to obtain percentages. */ State = Name[2:nrow(Name)]; Pct = 100*Count[2:nrow(Count),] / Count[1,]; Pct[loc(Pct=0)] = .; /* convert 0 to missing */ /* 3. Compute quantiles for current number of representatives */ r = Pct[,ncol(Pct)]; /* last column */ call qntl(qntl, r, {.2 .4 .6 .8}); /* P20-P80 */ q = bin(r, 0 // qntl // max(r) ); /* quintiles */ /* 4. Output columns for easy plotting */ State = repeat( State, 1, ncol(Pct) ); Year = repeat( Year, nrow(Pct), 1 ); Quintile = repeat( q, 1, ncol(Pct) ); create RepPct var {"Year" "Pct" "State" "Quintile"}; append; close RepPct; quit; ods graphics / width=1000 height=800; /* uncomment next line to vary the line styles: ods html style=listing; */ ods graphics / antialiasmax=1200; title "Representatives in Congress by State"; proc sgpanel data=RepPct; label Pct = "Percentage of US Representatives"; panelby Quintile / columns=1 uniscale=column; series x=Year y=Pct / group=State curvelabel; colaxis grid display=(nolabel); run;