130 likes | 548 Views
A Brief Introduction to PROC TRANSPOSE prepared by Voytek Grus for. SAS user group, Halifax November 26, 2009. What is data transposition?. Matrix notation: : X T Excel: copy/paste/transpose command or pivot tables. Example of a simple data transposition:.
E N D
A Brief Introduction to PROC TRANSPOSEprepared byVoytek Grusfor SAS user group, Halifax November 26, 2009
What is data transposition? • Matrix notation: : XT • Excel: copy/paste/transpose command or pivot tables. • Example of a simple data transposition:
Examples of Complex data transpositions Full Transp. Interleaved Dataset
Why do we transpose data? • For data presentation purposes. • To merge datasets with diverse structures • To re-design databases • efficiency gains in programming code and processing time.
Transposing data to streamline SAS calc. and programming code. Cross-sectional data base design Sequential data base design Data Step Array def. Do loop If condition Then output; Run; Proc Transpose This db design is more amenable to sequential data processing using SAS procs with BY statements Proc means, proc regression, proc univariate etc.. Data Step type of processing Data test2; Set test1; Sum= var1+ var2+var3;run;
Syntax of Proc Transpose PROC TRANSPOSE (DATA=input-data-set <LABEL=label> <LET> <NAME=name> ) OUT=output-data-set (drop = _label_ _name_) <PREFIX=prefix>; BY <DESCENDING> variable-1WHERE … (Conditions) … ; VAR (options: list variables, _all_, blank); ID variable; IDLABEL variable; COPY variable(s); • Beware of pitfalls of missing observations and/or duplicate entries in the id variable
SAS Help Tip • Examples: TRANSPOSE Procedure • Example 1: Performing a Simple Transposition • Example 2: Naming Transposed Variables • Example 3: Labeling Transposed Variables • Example 4: Transposing BY Groups • Example 5: Naming Transposed Variables When the ID Variable Has Duplicate Values • Example 6: Transposing Data for Statistical Analysis
An example of proc transpose application in pricing and cost studies from the utility industry • Use divers data bases in pricing studies • Load Research (sample data of 15 min readings) • Power Production (hourly costs) • CIS (monthly records)
Real Life Example (slide 1) • proc transpose data=bd_ets out=bd_ets2; var kwhs kws; • id season daytime _name_; • by year class customer bf psmadj; run;
Real Life Example (slide 2) proctranspose data=bd_ets out=bd_ets2; • var kwhs kws; by year class customer bf psmadj season daytime; run; • data bd_ets2; set bd_ets2; newname=left(right(_name_)||left(season)||left(daytime));run;
Real Life Example (slide 3) • procsort data=bd_ets2 out=bd_ets3; • by class year customer bf psmadj newname;run; • proctranspose data=bd_ets3 out=bd_ets3(drop=_name_); • var col1;id newname; by class year customer bf psmadj;run;