11-19-2016 08:06 PM
I have a dataset I'd like to transpose:
I used the following code and get the table below:
proc transpose data=gep2 out=gep3 NAME=Year; id countrycode; var _2001-_2018; run;
Isn't NAME=Year supposed to rename my first column? If not, what is the best way to rename this variable?
11-20-2016 12:16 AM - edited 11-20-2016 12:17 AM
Change the label, either in your proc print, graphing procedure, data step or proc datasets.
label year = 'Year';
I'm surprised your graph is correct, since you have a categorical/character variable. You may want to consider switching it to a numeric variable.
Your transpose is simple, perhaps consider a data step to transpose instead to move to a fully long solution? It would be easier to create graphs and such using GROUP or BY option but I'm not sure what you're doing later on. Untested because you haven't posted sample data in text form and I'm not typing out data
data want; set have; array yrs(*) _2001-_2018; do i=1 to dim(yrs); Value = yrs(i); Year=input(compress(vname(yrs(i)), , 'kd'), 8.); output; end; drop _2001 - _2018; run;
Your graphing procedure would then be:
proc sgplot data=want; series x=year y=value/group=countryName; run;quit;
In general, the graphs from SGPLOT are of better quality than SAS/GRAPH procedures.
11-20-2016 05:03 PM
Another way to switch to long format
proc transpose data=gep2 out=gep3 NAME=YearStr; by CountryName CountryCode notsorted; var _2001-_2018; run; data gep4; set gep3; Year = input(substr(yearStr, 2), 4.0); rename col1=Value; drop yearStr _name_; run; proc sgplot data=gep4; series x=year y=value / group=CountryName; run;