Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotating a SAS data set

Status
Not open for further replies.

sniggih

Technical User
Jan 23, 2002
22
0
0
US
I am new to SAS so I need some help.

I have a database that has a summary of members in age/gender categories. However the age/gender categories are in columns and I need to rotate the data. So that in one column I have membership and in the other column I have the age/gender category that goes with that membership.

This is what I did...

data util.asb2 (drop=C0000 C0101 C0209 C1017 F1819 F2024 F2529 F3034 F3539 F4044 F4549
F5054 F5559 F6064 F65Up M1819 M2024 M2529 M3034 M3539 M4044 M4549
M5054 M5559 M6064 M65Up);

set util.asb;

array AgeSex{26} C0000 C0101 C0209 C1017 F1819 F2024 F2529 F3034 F3539 F4044 F4549
F5054 F5559 F6064 F65Up M1819 M2024 M2529 M3034 M3539 M4044 M4549
M5054 M5559 M6064 M65Up ;

do ASCat=1 to 26;
Mems= AgeSex{ASCat};
output;
end;

run;

This worked however in ASCat column I get numbers from 1 to 26. What I would really like to get is the column names (i.e. C000, C0101). What is the best way to do accomplish this?
 
sniggih,
From what I understood from your code is that, you will get two columns in your output
Ascat: which will have values 1 to 26(it is like saying do i=1 to 26 and the value of i would be 1 to 26)
Mems: would have the VALUE of each of the columns in your array, not the actual names of the columns.
If you don't want the VALUE but want the column NAMES then you would have to acutally assigned the names to the variable Mems,
so it would be like

Mems="C000"; output;

or something like this
declare a Character array
array $ agesex "C000" "C010"(Please note I am not certain of the syntex)

do over agesex;
mems = agesex; output;
end;

I think this should do it.

HTH-SK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top