BookmarkSubscribeRSS Feed
KarimaTouati
Obsidian | Level 7

I have the following data.  Table1 which is symetric and the number of rows is equal to the numbers of columns.


table1.PNG

 

 

 

 

 

 

 

I want to make a transpose, so columns become rows and vice versa without using the Transpose function since I don't have IML Licence.

 

Can you help me please ? 

4 REPLIES 4
Rick_SAS
SAS Super FREQ

Here is the conversion from "wide format" (many columns) to "long format":

 

data Have;
input Annee Annee1-Annee7;
datalines;
1995 1 2 3 4 5 6 7
1996 1 2 3 4 5 6 .
1997 1 2 3 4 5 . .
1998 1 2 3 4 . . .
1999 1 2 3 . . . .
2000 1 2 . . . . .
2001 1 . . . . . .
;

data Want;
set Have;
array Y[7] Annee1-Annee7;
i = _N_;
do j = 1 to dim(Y) - i + 1;
   Value = Y[j];
   output;
end;
keep Annee i j Value;
run;

I'll bet that if you think about it you will be able to go the other way without help. Give it a try!

FreelanceReinh
Jade | Level 19

Hello @KarimaTouati and welcome to the SAS Support Communities!

 

The TRANSPOSE procedure does exactly what you describe:

 

proc transpose data=have out=want;
run;
ed_sas_member
Meteorite | Level 14

Hi @KarimaTouati 

 

In addition to @FreelanceReinh's answer, I would also add a COPY statement not to transpose the "annee" column:

data have;
	infile datalines truncover;
	input annee annee1-annee7;
	datalines;
1995 23758 49114 68582 79840 86298 90566 92878
1996 31245 63741 90775 106439 115054 120210
1997 26312 57779 82451 95506 101664
1998 30470 65482 90973 103562
1999 49756 101587 136854
2000 50420 102735
2001 56762
;
run;
proc transpose data=have out=want (drop=_name_);
copy annee;
run;

 

jhammouda
Obsidian | Level 7

Hi Karima,

 

I do not know if you are aware of this, but there is a university version of SAS available for free, that will give you the transpose functionality. Here is the link.

 Good Luck

https://www.sas.com/en_us/software/university-edition.html

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1621 views
  • 4 likes
  • 5 in conversation