LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 7 Oct 2009 13:55:29 -0500
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: Output statement problem in array
Comments: To: Sophia Tong <sophiDT@hotmail.com>
In-Reply-To:  <200910071803.n97GKMeu007459@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

Your output statements at the end don't work, I don't think - or rather, they probably don't do what you think they do. As far as I know, they don't just change where any given output goes to. You probably need to simply remove them and change the earlier output statements to route to the appropriate datasets.

This works [though you don't quite specify a few things so I adjusted it a bit for expedience]: data have; input sex Wt_kg_Mean Wt_kg_StdDev BMI_Mean BMI_StdDev; datalines; 0 83.72496865 9.259684431 27.82611859 3.337137114 1 67.35882123 13.42571627 25.59401365 4.211461117 ;;;;; run;

%LET Std= Wt_kg_StdDev BMI_StdDev; %LET VName= Wt_kg_Mean BMI_Mean;

DATA MNs_M(Keep=Measure Male) MNs_F(Keep=Measure Female); SET have; ARRAY VarsName {*} &VName ; ARRAY VarStd {*} &Std; do i = 1 to dim(varstd); measure = vname(Varsname[I]); IF SEX=0 THEN DO; Male=CAT(ROUND( VarsName(I), .1), ' ', ROUND(VarStd(I), .1)); OUTPUT MNs_M; END; IF SEX=1 THEN DO; Female= CAT(ROUND(VarsName(I), .1), ' ', ROUND(VarStd(I), .1)); OUTPUT MNs_F; END; end; RUN;

You could also do this in two other, more flexible, ways, if there's a benefit to that; either using a temporary array, or using a pair of PROC TRANSPOSE steps, to transpose it to vertical, and then combine records with the same pre-name.

-Joe

On Wed, Oct 7, 2009 at 1:03 PM, Sophia Tong <sophiDT@hotmail.com> wrote:

> Dear listers, > > I am trying to re-organize my the output data from proc means and here are > the data(named MNs below)look like: > > sex Wt_kg_Mean Wt_kg_StdDev BMI_Mean BMI_StdDev > 0 83.72496865 9.259684431 27.82611859 3.337137114 > 1 67.35882123 13.42571627 25.59401365 4.211461117 > > I am trying to transpose into colmns with mean std by sex. Below is my > code for it: > > %LET Std= Age_StdDev Wt_kg_StdDev BMI_StdDev; > %LET VName= Age_Mean Wt_kg_Mean BMI_Mean; > > DATA MNs_M(Keep=Measure Male) MNs_F(Keep=Measure Female); > SET MNs; > ARRAY VarN {*} &VarsN; > ARRAY VarsName {*} &VName ; > ARRAY VarStd {*} &Std; > > DO I = 1 to DIM(VarN); > Measure=VNAME(VarN(I)); > IF SEX=0 THEN DO; > Male=CAT(ROUND( VarsName(I), .1), ' ', ROUND(VarStd(I), .1)); > OUTPUT; > END; > IF SEX=1 THEN DO; > Female= CAT(ROUND(VarsName(I), .1), ' ', ROUND(VarStd(I), .1)); > OUTPUT; > END; > END; > IF SEX=0 THEN OUTPUT MNs_M; > ELSE OUTPUT MNs_F; > RUN; > > The re-organized data look like this: > > Measure Male > > Wt_kg 82.5 13.4 > BMI 26.2 3 > BMI 26.2 3 > > Wt_kg > BMI > > As you can see, BMI, which is the last variable repeated output twice, what > step should I take to avoid this problem? > > Thanks in advance, > Sophia >


Back to: Top of message | Previous page | Main SAS-L page