Proc Transpose issue with Name

Reply
Occasional Contributor
Posts: 13

Proc Transpose issue with Name

I have a dataset I'd like to transpose:

gep2.PNG

 

I used the following code and get the table below:

proc transpose data=gep2
out=gep3
NAME=Year;
id countrycode;
var _2001-_2018;
run;

gep3.PNG

 

Isn't NAME=Year supposed to rename my first column? If not, what is the best way to rename this variable?

Super User
Posts: 1,111

Re: Proc Transpose issue with Name

You could use rename option like below

proc transpose data=gep2 out=gep3(rename=(_NAME_=Year));
id countrycode;
var _2001-_2018;
run;
Thanks,
Jag
Occasional Contributor
Posts: 13

Re: Proc Transpose issue with Name

Hi Jag - thanks for the suggestion; unfortunately, it didn't work. I keep seeing Name of Former Variable.

 

 

Grand Advisor
Posts: 9,578

Re: Proc Transpose issue with Name

Your code is right.
What you saw is LABEL not variable NAME.
Right click the table and check column attribution .


Occasional Contributor
Posts: 13

Re: Proc Transpose issue with Name

Thanks, when i do a proc print it does show up correctly; however, when i try plotting I gett the same "Name of Former Variable"

 

gepplot.PNG

Grand Advisor
Posts: 17,351

Re: Proc Transpose issue with Name

[ Edited ]

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 Smiley Happy

 

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. 

 

 

 

Respected Advisor
Posts: 4,607

Re: Proc Transpose issue with Name

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;

(untested)

PG
Ask a Question
Discussion stats
  • 6 replies
  • 287 views
  • 1 like
  • 5 in conversation