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 (April 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 20 Apr 2011 11:59:39 -0400
Reply-To:     "Viel, Kevin" <kviel@SJHA.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Viel, Kevin" <kviel@SJHA.ORG>
Subject:      Re: counts into a macro
In-Reply-To:  <BANLkTi=zF7z37y0EVny2h7fFvaVi5SOpGA@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > SAS_learner > Sent: Tuesday, April 19, 2011 6:10 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: counts into a macro > > Hello all, > > I know that data _null_ does not like to get the data into macros , but I > need to something like this (below) > > proc sql; > select count(usubjid) into :_n1 from subjinfo where trtsort = 1; > select count(usubjid) into :_n2 from subjinfo where trtsort = 2; > select count(usubjid) into :_n3 from subjinfo where trtsort = 3; > select count(usubjid) into :_n4 from subjinfo where trtsort = 4; > select count(usubjid) into :_n5 from subjinfo where trtsort = 5; > select count(usubjid) into :_n6 from subjinfo where trtsort = 6; > select count(usubjid) into :_n9 from subjinfo where trtsort ^= 1; > quit; > > and want avoid giving trtsort = and into _n as the trtsort is changing > for > the study . Is there a better way to do it. > > thanks > sl

I respectively disagree that the FREQ procedure would be clearer to a legacy programmer than an SQL procedure approach with a GROUP BY clause. At any rate, these situation is why we have comments and example code :)

The suggestions we might offer depend on the use and the nature of how "trtsort" changes for the study.

I might use:

Proc SQL ; Select CatX( "/" , trtsort , Count( * )) Into : trtsort_count_list Separated by " " From SubInfo Group By TrtSort ; Quit ;

171 Proc SQL NoPrint ; 172 Select CatX( "/" , trtsort , Count( * )) Into : trtsort_count_list Separated by " " 173 From SubInfo 174 Group By TrtSort 175 ; 176 Quit ; NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds

177 178 %Put &trtsort_count_list. ; 1/2 2/10 3/4 4/3 5/10 6/10 7/6 8/6 9/1 10/1 179 180 %Let I = 1 ; 181 %Let tsort = %Scan( %Scan( &trtsort_count_list. , &i. , %Str( )) , 1 , / ) ; 182 183 %Let _n&tsort. = %Scan( %Scan( &trtsort_count_list. , &i. , %Str( )) , 2 , / ) ; 184 185 %Put _n&tsort. = &&_n&tsort. ; _n1 = 2 186 187 188 %Let I = 5 ; 189 %Let tsort = %Scan( %Scan( &trtsort_count_list. , &i. , %Str( )) , 1 , / ) ; 190 191 %Let _n&tsort. = %Scan( %Scan( &trtsort_count_list. , &i. , %Str( )) , 2 , / ) ; 192 193 %Put _n&tsort. = &&_n&tsort. ; _n5 = 10 194 195 196 %Let I = &SQLObs. ; 197 %Let tsort = %Scan( %Scan( &trtsort_count_list. , &i. , %Str( )) , 1 , / ) ; 198 199 %Let _n&tsort. = %Scan( %Scan( &trtsort_count_list. , &i. , %Str( )) , 2 , / ) ; 200 201 %Put _n&tsort. = &&_n&tsort. ; _n10 = 1

It depends on how I would use it, but most likely within a %DO loop in a macro...

-Kevin

Kevin Viel, PhD Senior Research Statistician Patient Safety & Quality International College of Robotic Surgery Saint Joseph's Translational Research Institute

Saint Joseph's Hospital 5671 Peachtree Dunwoody Road, NE, Suite 330 Atlanta, GA 30342

(678) 843-6076: Direct Phone (678) 843-6153: Facsimile (404) 558-1364: Mobile kviel@sjha.org Confidentiality Notice: This e-mail, including any attachments is the property of Catholic Health East and is intended for the sole use of the intended recipient(s). It may contain information that is privileged and confidential. Any unauthorized review, use, disclosure, or distribution is prohibited. If you are not the intended recipient, please delete this message, and reply to the sender regarding the error in a separate email.


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