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 (August 2006, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 31 Aug 2006 13:15:17 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: COMPRESS function working differently in Data Step and Macro
Comments: To: job.alerte@GMAIL.COM
In-Reply-To:  <1157019624.955961.163010@h48g2000cwc.googlegroups.com>
Content-Type: text/plain; format=flowed

Catherine,

The two arent the same, %SysFunc( Compress( &xxx , %Str( ) ) ) will compress out all the blanks, while %CmPress( &xxx ) will shrink double spaces into one space.

Toby Dunn

When everything is coming at you all at once, your in the wrong lane.

A truly happy person is someone who can smile and enjoy the scenery on a detour.

From: Cat <job.alerte@GMAIL.COM> Reply-To: Cat <job.alerte@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: COMPRESS function working differently in Data Step and Macro Date: Thu, 31 Aug 2006 03:20:25 -0700

Hi Jack,

%sysfunc(compress()) can be replaced by %cmpress() .

Regards,

Catherine. ------------------------------------- Biostatistician / SAS pharma programer www.keyrusbiopharma.fr

Jack Clark wrote: > I moved the closing parenthesis for the %BQUOTE function, and the HTML files > are now named properly! > > > body="nh_%sysfunc(compress(%bquote(%sysfunc(putc(%scan(&cvals,&ci),$cnty.))) > ,' ','p')).html" > > But I am back to the WARNING message in the log (WARNING: In a call to the > COMPRESS function or routine, the modifier "'" not valid.). If anyone has > info on this, please let me know. > > > To respond to Arlid's suggestion about changing the formatted values, the > formatted values are used in other places. Specifically in titles of output > reports, where the it is necessary to maintain the spaces and punctuation. > I could create a separate format, but I wanted to find a programmatic way > around the issue before falling back on that. > > Thanks again. > > > Jack Clark > Research Analyst > Center for Health Program Development and Management > University of Maryland, Baltimore County > > > -----Original Message----- > From: Guido T [mailto:cymraegerict@gmail.com] > Sent: Wednesday, August 30, 2006 9:39 AM > To: Jack Clark > Cc: SAS-L@listserv.uga.edu > Subject: Re: COMPRESS function working differently in Data Step and Macro > Code > > Hi Jack, > > Try quoting the bit with the quote ... something like ... > > compress(%bquote(%sysfunc(putc(%scan(&cvals,&ci),$cnty.)),' p')) > > regards > ++ Guido > > > On 30/08/06, Jack Clark <JClark@chpdm.umbc.edu> wrote: > > Good morning, > > > > > > > > I am trying to use the Compress function to remove spaces, periods and > > apostrophes from a text string. It seems to be working fine in a Data > Step, > > but it is returning Warnings in the log when I use it with %sysfunc in a > > macro program. > > > > > > > > I have simplified my project here, but tried to maintain the general idea > of > > what I am trying to accomplish. I have also supplied sample data that can > > be cut, pasted and run in SAS (you may have to change the Path= for the > ODS > > HTML statement). > > > > > > > > I have a data set that contains County Codes, and a character format > > ($cnty.) that has the actual names of the counties. One thing that I > > believe is contributing to my woes is that some of the county names > contain > > apostrophes (which SAS is seeing as a single quote). In a data step, I > > create a new variable called DRILL which will be the name of html files > > created later in the job. The COMPRESS function works as expected here, > > removing the spaces and punctuation from the formatted County name. > > > > > > > > proc format; > > > > value $cnty > > > > "02" = "Anne Arundel" > > > > "03" = "Baltimore" > > > > "16" = "Prince George's" > > > > "18" = "St. Mary's" > > > > "99" = "Out of State" > > > > ; > > > > run; > > > > > > > > data test; > > > > infile cards missover; > > > > input @01 cntycode $char02. > > > > ; > > > > cntyname = put(cntycode,$cnty.); > > > > drill = "href='nh_"||compress(cntyname,' ','p')||".html'"; > > > > cards; > > > > 02 > > > > 03 > > > > 16 > > > > 18 > > > > 99 > > > > ; > > > > run; > > > > > > > > proc print data = test; > > > > run; > > > > > > > > > > > > > > > > Next, the goal is to use ODS HTML to generate an HTML file for each value > of > > county code. I use PROC SQL to load macro variables with the number of > > unique county codes and the value of the county codes. Then a macro > program > > to generate the HTML files. The BODY= parameter on the ODS statement is > > where I am running into issues. My attempt is to %SCAN the macro variable > > for the appropriate county code based on the loop increment, apply the > $cnty > > format, and COMPRESS to remove spaces and punctuation. > > > > > > > > * load macro variables with number of county codes and their values ; > > > > proc sql noprint; > > > > select count(*), cntycode > > > > into :ccnt, :cvals separated by ' ' > > > > from (select distinct cntycode > > > > from test) > > > > ; > > > > quit; > > > > > > > > %put &ccnt; > > > > %put &cvals; > > > > > > > > > > > > * macro to write out 1 html page per county ; > > > > * the html files should be named 'nh_CountyName.html (with spaces and > > punctuation removed from county name) ; > > > > %macro sasl; > > > > > > > > > > > > %do ci = 1 %to &ccnt; > > > > ods html > > > > path='d:\dss_behave'(url=none) > > > > body="nh_%sysfunc(compress(%sysfunc(putc(%scan(&cvals,&ci),$cnty.)),' > > ','p')).html"(title="SAS-l Example") > > > > ; > > > > > > > > /* misc sas procs to generate reports on html page */ > > > > proc print data = test; > > > > where cntycode = "%scan(&cvals,&ci)"; > > > > run; > > > > > > > > ods html close; > > > > %end; > > > > > > > > %mend sasl; > > > > > > > > %sasl; > > > > > > > > > > > > This seems to work fine until the code hits one of the county names with > an > > apostrophe - then the job crashes. Additionally, there are messages in > the > > log about the modifiers I am using with the COMPRESS function being > invalid > > (WARNING: In a call to the COMPRESS function or routine, the modifier "'" > > not valid.). > > > > > > > > Just as a note, I have tried different variations on the COMPRESS function > > all with the same WARNING message and result: > > > > > > > > > "nh_%sysfunc(compress(%sysfunc(putc(%scan(&cvals,&ci),$cnty.)),' > > ','p')).html" > > > > > > > "nh_%sysfunc(compress(%sysfunc(putc(%scan(&cvals,&ci),$cnty.)),,'sp')).html" > > > > > > > "nh_%sysfunc(compress(%sysfunc(putc(%scan(&cvals,&ci),$cnty.)),,'ka')).html" > > > > > > > > > > > > You should be able run my code to generate the log WARNING and ERROR > > messages, but if you can't I can send a log. I would appreciate feedback > > that focuses on the meaning of the WARNING messages related to the > COMPRESS > > function or suggestions on how to generate the value of the BODY= > attribute > > in the desired format. > > > > > > > > Thank you. > > > > > > > > > > > > Jack Clark > > > > Research Analyst > > > > Center for Health Program Development and Management > > > > University of Maryland, Baltimore County > >


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