BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
superbug
Quartz | Level 8

As attached, my data named "try" was generated by "proc summary" in previous step. Now I want to use "proc transpose" to reformat the data using the following code

 

proc sort data=try; by level id year; run;

proc transpose data=try
out=try1;
var nclass;
by level id year;
run;

 

But got the result as the attached data try1. 

 

I seems there is issue of  my "try" data. please help.

 

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Not clear what you want, but you probably want to use YEAR as an ID variable instead of BY variable.

proc transpose data=try out=want prefix=Year_ ;
  by level id ;
  id year;
  var nclass;
run;

proc print data=want; run;
                                 Year_    Year_    Year_    Year_    Year_    Year_    Year_
Obs    level     id     _NAME_     2013     2014     2015     2016     2017     2018     2019

 1      PT      0001    nclass      44       37       45       44       43       39       41
 2      PT      0002    nclass      55       53       54       55       49       51       56
 3      PT      0008    nclass      28       42       38       35       38       40       38

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Not clear what you want, but you probably want to use YEAR as an ID variable instead of BY variable.

proc transpose data=try out=want prefix=Year_ ;
  by level id ;
  id year;
  var nclass;
run;

proc print data=want; run;
                                 Year_    Year_    Year_    Year_    Year_    Year_    Year_
Obs    level     id     _NAME_     2013     2014     2015     2016     2017     2018     2019

 1      PT      0001    nclass      44       37       45       44       43       39       41
 2      PT      0002    nclass      55       53       54       55       49       51       56
 3      PT      0008    nclass      28       42       38       35       38       40       38
superbug
Quartz | Level 8

@Tom 

That's a good point.

Thanks much for your help!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 711 views
  • 0 likes
  • 2 in conversation