Date: Thu, 16 Oct 1997 00:08:13 -0700
Reply-To: Andrew James Llwellyn Cary <ajlcary@CARYCONSULTING.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Andrew James Llwellyn Cary <ajlcary@CARYCONSULTING.COM>
Subject: Re: PROC Transpose
Content-Type: text/plain; charset="us-ascii"
Here is two different solutions:
Data step;
DATA MCCCI.PDSTRAN;
LENGTH VARNAME $8 MEMNAME $8;
ARRAY V mbrnm1-mbrnm13;
SET work.pdsin;
DO OVER V;
MEMNAME=V;
CALLVNAME(V,VARNAME);
OUTPUT;
END;
KEEP DSN MEMNAME VARNAME;
RUN;
The data doesn't even have to be sorted and it takes one pass. It also copes with more then two rows per
dataset name.
PROC TRANSPOSE SOLUTION
proc transpose data=work.pdsin out=work.junk;
by dsname;
var mbrnm1-mbrnm13;
run;
proc transpose data=work.junk out=mccc1.pdstrn (where=(col1 ne ''));
by dsname _NAME_;
var COL1-COL2;
run;
Two passes through after sorting. Hmmm.
On Wednesday, October 15, 1997 12:43 PM, RICHARD STEVENS[SMTP:RSTEVENS@BCBSCT.COM] wrote:
>Hi all,
>
>This probably has a simple solution, but I can't seem to see it. The bottom
>line is I want the the results to have one COL1 not more than one. I have
>tried this on MVS v6.09 and MS Windows 3.1, SAS 6.11 and get the
>same results. The manual example shows that this is possible, but using
>the example, I don't get the results. (SAS Procedures Guide v6 3rd ed
>p597).
>
>The files and code follow:
>
>SAS data -- mccc1.pds
>OBS MBRNM1 MBRNM2 MBRNM3 MBRNM4 MBRNM5
>MBRNM6 . . .
>
> 1 @JOBX951 @JOB01X @JOB02 CHCMEMRL CLMX01
>CLM01
> 2 SEASONT1 SEASON01 SEASON02 SEASON03 SEASON99
> TEMP01
>
>
>MBRNM10 MBRNM11 MBRNM12 MBRNM13 DSNAME
>
>EMUC03 EMUC04 FORMAT HEDISCL
>A438U11.CONTAIN.CODE
> A438U11.CONTAIN.CODE
>
>I tried rearranging the variables to see if that helped, it didn't.
>proc sql;
>create table work.pdsin as
> select
>dsname,mbrnm1,mbrnm2,mbrnm3,mbrnm4,mbrnm5,mbrnm6,mbrnm7
> ,mbrnm8,mbrnm9,mbrnm10,mbrnm11,mbrnm12,mbrnm13
> from mccc1.pds
>;
>
>proc transpose data=work.pdsin out=mccc1.pdstrn let;
> by dsname;
> var mbrnm1-mbrnm13;
>run;
>
>The output: I would like to see the values under _NAME_ repeated with
>the values COL2, therefore no COL2 or greater in the out file.
>OBS DSNAME _NAME_ COL1 COL2
>
> 1 A438U11.CONTAIN.CODE MBRNM1 @JOBX951 SEASONT1
> 2 A438U11.CONTAIN.CODE MBRNM2 @JOB01X SEASON01
> 3 A438U11.CONTAIN.CODE MBRNM3 @JOB02 SEASON02
> 4 A438U11.CONTAIN.CODE MBRNM4 CHCMEMRL SEASON03
> 5 A438U11.CONTAIN.CODE MBRNM5 CLMX01 SEASON99
> 6 A438U11.CONTAIN.CODE MBRNM6 CLM01 TEMP01
> 7 A438U11.CONTAIN.CODE MBRNM7 CONTENTS TSODB2C
> 8 A438U11.CONTAIN.CODE MBRNM8 EMUC01
> 9 A438U11.CONTAIN.CODE MBRNM9 EMUC02
> 10 A438U11.CONTAIN.CODE MBRNM10 EMUC03
> 11 A438U11.CONTAIN.CODE MBRNM11 EMUC04
> 12 A438U11.CONTAIN.CODE MBRNM12 FORMAT
> 13 A438U11.CONTAIN.CODE MBRNM13 HEDISCL
>
>
>Thanks for you assistance.
>Richard
>
>
---------------------------------------
Andrew J. L. Cary
Senior Curmudgeon
Cary Consulting Services
http://www.caryconsulting.com
|