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 (January 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 7 Jan 2011 10:17:43 -0500
Reply-To:   "Kirby, Ted" <ted.kirby@LEWIN.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Kirby, Ted" <ted.kirby@LEWIN.COM>
Subject:   Re: NRows was (RE: Re: Macro Quoting Issue (I think) - Problem with CALL EXECUTE parameter values with Apostrophe, Comma)
In-Reply-To:   A<9F0A90FE1B47E74DB4DF72EC940E33AC0241BCB7@EMBX-CHAM4.cdc.gov>
Content-Type:   text/plain; charset="us-ascii"

Ron,

I sent an errata (well, actually a "nevermind") follow-up post. I noticed the SET statement after I sent the original post. However, thanks for the explanation as to why the variable can be in the program ahead of the statement that defines it.

Ted Kirby, Consultant, The Lewin Group, Inc. 3130 Fairview Park, Suite 800 Falls Church, VA 22042 Phone: (703)269-5507 Fax: (703)269-5501 e-mail: ted.kirby@lewin.com

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Fehd, Ronald J. (CDC/OCOO/ITSO) Sent: Friday, January 07, 2011 8:39 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: NRows was (RE: Re: Macro Quoting Issue (I think) - Problem with CALL EXECUTE parameter values with Apostrophe, Comma)

do I = 1 to Nrows; set &InData. nobs = Nrows; .......................^^^^^

Ah, no. SAS had already finished 'read'ing the set statement during compile time the do statement was 'read' during the execution phase.

Ron Fehd the compile/execute maven "Which came first: compile or execute?"

> -----Original Message----- > From: owner-sas-l@listserv.uga.edu [mailto:owner-sas- > l@listserv.uga.edu] On Behalf Of Kirby, Ted > Sent: Friday, January 07, 2011 7:45 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: RE: NRows was (RE: Re: Macro Quoting Issue (I think) - Problem > with CALL EXECUTE parameter values with Apostrophe, Comma) > > In the words of Rosanne Rosannadanna: > > Nevermind > > I just noticed that "Nrows" was defined in the SET statement that > immediately FOLLOWED the DO statement. I was expecting the definition > of the variable BEFORE it appeared in the program. I forget about the > DATA steps ability to sometimes "jump back and forth" in the code. > > -----Original Message----- > From: Kirby, Ted > Sent: Friday, January 07, 2011 7:36 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: NRows was (RE: Re: Macro Quoting Issue (I think) - Problem > with > CALL EXECUTE parameter values with Apostrophe, Comma) > > In the paper cited below (http://tinyurl.com/6mmqpj), the > "make-array-symputx.sas" example uses a variable "Nrows." However, I > do > not see where this variable is defined. > > I thought it might be some sort of system variable that SAS for which > SAS knows its definition. I checked the SAS online documentation (that > comes with SAS) and found that when "Nrows" was used as a variable, it > was always defined somewhere in the example program. (There was an > NROW function that needs a matrix as its argument and several PROCS > where NROWS was an option.) > > Am I missing something? > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Fehd, Ronald J. (CDC/OCOO/ITSO) > Sent: Thursday, January 06, 2011 12:09 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Macro Quoting Issue (I think) - Problem with CALL EXECUTE > parameter values with Apostrophe, Comma > > summary: > 1. in calling routine, remove special characters in parameters > 2. expand in the subroutine > > i.e. > > 1. change QUEEN ANNE'S to QUEEN ANNE!S > 2. change QUEEN ANNE!S back to QUEEN ANNE'S > > see other tricks in this paper: > > List Processing Basics Creating and Using Lists of Macro Variables > > Tiny Url: http://tinyurl.com/5p3j2z for this page > > http://tinyurl.com/6mmqpj for paper > > http://www2.sas.com/proceedings/forum2007/113-2007.pdf > > SGF 2007, paper 113, section: Hands On Workshops > > List Processing Basics: Creating and Using Lists of Macro Variables > * Ronald J. Fehd > > * Art Carpenter > > Ron Fehd the macro maven > > > > > -----Original Message----- > > From: owner-sas-l@listserv.uga.edu [mailto:owner-sas- > > l@listserv.uga.edu] On Behalf Of Jack Clark > > Sent: Thursday, January 06, 2011 10:17 AM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: Macro Quoting Issue (I think) - Problem with CALL EXECUTE > > parameter values with Apostrophe, Comma > > > > Hello and Happy New Year, > > > > > > > > This is a somewhat long post, but I have tried to clearly provide as > > much information as possible. I need some help with what I think may > > be > > a macro quoting issue. I have tried to simplify the code for this > > post. > > I am developing a SAS program which will select records from the > source > > data based on COUNTY and generate a report. > > > > > > > > A couple of notes > > > > - Some COUNTY names in the source data contain parentheses > and > > apostrophes > > > > - Some COUNTYs have multiple values in the source data, so > all > > must be selected when running for that county > > > > > > > > I have successfully written logic which allows me to select 1 county > > and > > the report is generated for that county (see below): > > > > > > > > * source data ; > > > > data test (drop=i); > > > > infile cards missover; > > > > input @01 countyname $16.; > > > > do i = 1 to 5; > > > > output; > > > > end; > > > > cards; > > > > BALTIMORE > > > > BALTIMORE (CITY) > > > > CARROLL > > > > QUEEN ANNE'S > > > > ; > > > > run; > > > > > > > > proc format; > > > > value $ cty '01' = "CARROLL" > > > > '02' = "BALTIMORE" > > > > '03' = "QUEEN ANNE'S" > > > > ; > > > > run; > > > > > > > > > > > > ** method #1 - use CALL SYMPUT to load macro variables and run report > > for single county ; > > > > %let ccode = 03; > > > > > > > > > > > > data _null_; > > > > countyt = put("&ccode.",$cty.); > > > > if "&ccode." = "02" then clist = "'BALTIMORE','BALTIMORE (CITY)'"; > > > > else clist = quote(trim(countyt)); > > > > call symput('countyt1',countyt); > > > > call symput('clist1',clist); > > > > run; > > > > > > > > title1 "METHOD #1 - Records from TEST Where COUNTYNAME = > > %bquote(&countyt1.)"; > > > > proc print data = test; > > > > where countyname in (&clist1.); > > > > run; > > > > > > > > > > > > > > > > Now I have to add the ability for the program to generate reports by > > COUNTY for multiple counties (or ALL counties). My initial strategy > > was > > to wrap the reporting code in macro, generate a data set that > contains > > one record per COUNTY to be run (with the parameters needed) and then > > use CALL EXECUTE to generate the reporting for each COUNTY. I added > > the ALL category to the format, so user can select to run ALL > counties. > > > > > > > > > > The code below works when CARROLL is selected as the COUNTY, but > fails > > for BALTIMORE and QUEEN ANNE'S. I believe BALTIMORE is failing > because > > of the comma "," in the value of CLIST when the CALL EXECUTE runs. > SAS > > is seeing the comma as separating macro parameters in the CTYRPT > macro > > instead of part of the CLIST2 parameter. I believe QUEEN ANNE'S is > > failing because of the apostrophe. I have tried %bquote around > COUNTYT > > in the CALL EXECUTE (and many other variations), but can't seem to > get > > it. > > > > > > > > If someone can tell me how to correct the process below, I would > > appreciate it. Or, if there are suggestions for a better approach I > am > > open to those as well. Thanks in advance. > > > > > > > > > > > > > > > > ** method #2 - build a data set to use with CALL EXECUTE to run > report > > for multiple counties ; > > > > %let ccode = 03; > > > > > > > > proc format; > > > > value $ cty '01' = "CARROLL" > > > > '02' = "BALTIMORE" > > > > '03' = "QUEEN ANNE'S" > > > > '99' = "ALL" > > > > ; > > > > run; > > > > > > > > data driver; > > > > length countyt $25 clist $50; > > > > if "&ccode." in ("01","99") then do; > > > > countyt = "CARROLL"; > > > > clist = quote(trim(countyt)); > > > > output; > > > > end; > > > > if "&ccode." in ("02","99") then do; > > > > countyt = "BALTIMORE"; > > > > clist = "'BALTIMORE','BALTIMORE (CITY)'"; > > > > output; > > > > end; > > > > if "&ccode." in ("03","99") then do; > > > > countyt = "QUEEN ANNE'S"; > > > > clist = quote(trim(countyt)); > > > > output; > > > > end; > > > > run; > > > > > > > > %macro ctyrpt (countyt2=,clist2=); > > > > > > > > title1 "METHOD #2 - Records from TEST Where COUNTYNAME = > > %bquote(&countyt2.)"; > > > > proc print data = test; > > > > where countyname in (&clist2.); > > > > run; > > > > > > > > %mend ctyrpt; > > > > > > > > > > > > data _null_; > > > > set driver; > > > > call execute('%ctyrpt(countyt2='||countyt||',clist2='||clist||')'); > > > > run; > > > > > > > > > > > > ******* log when I run for COUNTY name with apostrophe.... > > > > > > > > 472 > > > > 473 data _null_; > > > > 474 set driver; > > > > 475 call > > execute('%ctyrpt(countyt2='||countyt||',clist2='||clist||')'); > > > > 476 run; > > > > > > > > NOTE 49-169: The meaning of an identifier after a quoted string may > > change in a future SAS > > > > release. Inserting white space between a quoted string > > and > > the succeeding > > > > identifier is recommended. > > > > ERROR: Macro parameter contains syntax error. > > > > NOTE: The SAS System stopped processing this step because of errors. > > > > NOTE: There were 1 observations read from the data set WORK.DRIVER. > > > > NOTE: DATA statement used (Total process time): > > > > real time 0.00 seconds > > > > cpu time 0.00 seconds > > > > > > > > > > > > NOTE: CALL EXECUTE routine executed successfully, but no SAS > statements > > were generated. > > > > > > > > > > > > ******* log when I run for BALTIMORE - has multiple values in CLIST > and > > contains parentheses > > > > ******* I know this message is about the COMMA in the CLIST variable, > > but don't know how to fix it > > > > 508 > > > > 509 data _null_; > > > > 510 set driver; > > > > 511 call > > execute('%ctyrpt(countyt2='||countyt||',clist2='||clist||')'); > > > > 512 *call execute('%cty(countyt2='||%bquote(countyt)||')'); > > > > 513 run; > > > > > > > > ERROR: All positional parameters must precede keyword parameters. > > > > NOTE: The SAS System stopped processing this step because of errors. > > > > NOTE: There were 1 observations read from the data set WORK.DRIVER. > > > > NOTE: DATA statement used (Total process time): > > > > real time 0.00 seconds > > > > cpu time 0.00 seconds > > > > > > > > > > > > NOTE: CALL EXECUTE routine executed successfully, but no SAS > statements > > were generated. > > > > > > > > > > > > Jack Clark > > Senior Programmer > > phone: 410-455-6256 > > fax: 410-455-6850 > > jclark@hilltop.umbc.edu > > > > University of Maryland, Baltimore County > > Sondheim Hall, 3rd Floor > > 1000 Hilltop Circle > > Baltimore, MD 21250 > > > > Please consider the environment before printing this e-mail and/or > any > > attachments. > > > > > > Confidentiality Notice: This e-mail may contain information that is > > legally privileged and that is intended only for the use of the > > addressee(s) named above. If you are not the intended recipient, you > > are hereby notified that any disclosure, copying of this e-mail, > > distribution, or action taken in reliance on the contents of this e- > > mail and/or documents attributed to this e-mail is strictly > prohibited. > > If you have received this information in error, please notify the > > sender immediately by phone and delete this entire e-mail. Thank you. > ************* IMPORTANT - PLEASE READ ******************** > > This e-mail, including attachments, may include confidential and/or > proprietary information, > and may be used only by the person or entity to which it is addressed. > If the reader of this > e-mail is not the intended recipient or his or her authorized agent, > the reader is hereby > notified that any dissemination, distribution or copying of this e-mail > is prohibited. If you > have received this e-mail in error, please notify the sender by > replying to this message > and delete this e-mail immediately. > ************* IMPORTANT - PLEASE READ ********************

This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.


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