|
Rao ,
They should appear in one Row. But a slight modification and all is well:
I dont have V9 so I had to revert back to V8.2 code with the call symput.
And since you didnt give us a data set I use the SASHelp.Class data set.
Proc sql noprint ;
create table New like SASHELP.Class ;
select compress(Name) into : VarNames separated by ' '
from dictionary.columns
where Libname = 'WORK'
and Memname = 'NEW' ;
quit ;
data _null_ ;
call symput( '_efierr_' , put ( 0 , 8. ) ) ;
call symput( '_efirec_' , put ( 0 , 8. ) ) ;
if 0 then set New ;
file "C:\Documents and Settings\Toby Dunn\Desktop\Test.csv" dlm = ',' dsd
dropover lrecl = 32767 ;
put %sysfunc( tranwrd( "&VarNames" , %str( ) , %str(" ',' ") ) ) ;
do _n_ = 1 by 1 until (eof) ;
set SASHELP.Class (keep = &VarNames) end = eof ;
put (_all_) (:) ;
_efierr_ ++ _error_ ;
end ;
call symput( '_efierr_' , put( ^^_efierr_ , 8. ) ) ;
call symput( '_efirec_' , put( _n_ , 8. ) ) ;
stop ;
run ;
Toby Dunn
From: "rao bingi" <rao.bingi@gmail.com>
To: "toby dunn" <tobydunn@hotmail.com>
CC: SAS-L@listserv.uga.edu
Subject: Re: annoying error message in sas log
Date: Sun, 9 Apr 2006 21:18:53 -0400
Thanks to Paul and Toby
Finally i do not use proc export in this case. I have tried your code but i
open the .csv file the column names are appearing in one column.
Thanks
Rao
On 4/9/06, toby dunn <tobydunn@hotmail.com> wrote:
>
> Paul ,
>
> You may disagree with me on this but I would slightly modify your code (
> minor Changes) as you have some stuff in there that I personally think is
> well just way too much code:
>
>
> proc sql noprint ;
> create table dlm_model
> ( raw_term char (31) format=$31.
> , preferred_term char (36) format=$36.
> , wd_version char (04) format=$04.
> , term char (27) format=$04.
> , drug_code char (11) format=$11.
> , drug_name char (27) format=$27.
> ) ;
>
>
> select compress (name) into :dlm_vnames separated by " "
> from sashelp.vcolumn
> where libname = 'WORK' and memname = 'DLM_MODEL'
> ;
> quit ;
>
>
>
> data _null_ ;
> call symputn( '_efierr_' , 0 ) ;
> call symputn( '_efirec_' , 0 ) ;
>
> if 0 then set dlm_model ;
>
> file "c:\dt\test\xxx.csv" dlm = &dlm dsd dropover lrecl = 32767 ;
>
> put "%sysfunc( tranwrd( &VNames , %str( ) , %str( , ) ) ) " ;
>
> do _n_ = 1 by 1 until (eof) ;
> set whodrug_coded (keep = &VNames) end = eof ;
> put (_all_) (:) ;
> _efierr_ ++ _error_ ;
> end ;
>
> call symputn( '_efierr_' , ^^_efierr_ ) ;
> call symputn( '_efirec_' , _n_ ) ;
>
> stop ;
> run ;
>
>
>
>
> If one was using V9 I would personally go with %syserr. In my world
> knowing
> that there is an error is the most important part. Find what value is
> creating it ussually is a trivial matter (i.e. look at my log).
>
>
> Furthermore, if I was forced to use the code above I would deffinitly
> change
> the really crappy names of the two vars created by the symputx routines.
>
> call symputn ( '_efierr_' , 0 ) ;
> call symputn ( '_efirec_' , 0 ) ;
>
>
> Talk about unreadable and worthless.
>
>
> Toby Dunn
>
>
>
>
>
> From: "Paul M. Dorfman" <sashole@BELLSOUTH.NET>
> Reply-To: sashole@bellsouth.net
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: annoying error message in sas log
> Date: Sun, 9 Apr 2006 16:59:13 -0400
>
> Rao,
>
> I've got a few:
>
> 1. Kill the comment. It comments on self-explanatory code and hence is
> zero
> utility and all log pollution.
>
> 2. If you strongly object to violence and therefore are reluctant to go
> the
> #1
> route, replace the word ERROR with something else you are not going to
hit
> using
> your preferred log scan method. Any synonym for "error" will do fine. You
> can
> start with "mistake", "abnormality", or "irregularity", for example.
>
> 3. Better yet, change the comment altogether. First, comments should be
> brief.
> In this respect, "Detect errors" is much superior to "Set ERROR detection
> macro
> variable" and by the way will resolve your problem. Second, the line of
> code
> being commented has nothing to do with error detection. Instead, it
merely
> marks
> the fact an error has been already detected via the underlying software
by
> storing the character literal " 1" ('1' preceded by 11 blanks -
> on
> wisdom of doing so later) into the macro variable _EFIERR_. Hence a
> comment
> "Error? Set _efierr_ <- 1" is more to the point, but #1 still holds.
>
> 4. Finally, let us look at your step. This is a typical example of SAS
> code
> I
> call "maladroit", and the fact that PROC EXPORT may have created it for
> you
> is a
> poor excuse.
>
> First, even though the statements
>
> %let _EFIERR_ = 0;
> %let _EFIREC_ = 0;
>
> will not cause an error and serve the purpose, they do not belong to a
> DATA
> step. Either place them before the step, or, better, since you are using
> CALL
> SYMPUT routines anyway, be consistent and use it inside the step to
> initialize
> the macro variables.
>
> Second, you mix code and data (metadata in this case) within the step.
> This
> is a
> very poor practice making your code inherently difficult to read and
> debug.
> Instead of defining the order and attributes of the variables written to
> the
> delimited file within the DATA step, define all that beforehand using a
> model,
> empty SAS data set and then instruct the DATA step to read the metadata
> before
> it commences on processing records.
>
> Third, the already mentioned call symput('_EFIERR_',1) may cause you
grief
> should an error occur and you try to test whether &_erierr_ contains 1.
> Since
> you do not quote 1, it is a numeric literal, while anything to be stored
> in
> _efierr_ must be a string. SAS uses BEST12. for format it, and you end up
> storing '1' preceded by 11 blanks in _efierr_ (remember that SYMPUT,
> unlike
> the
> %LET statement, does not eradicate leading blanks). Plus, you will get a
> type
> conversion note in the log. Hence, put quotes around 1. If you have SAS9,
> you
> can use SYMPUTx routine
>
> Fourth, the same pertains to call symput('_EFIREC_',EFIOUT), although the
> leading blanks in the formatted values of EFIOUT are not as dangerous,
> since
> EFIOUT is purely informational. If you have SAS9, you can use SYMPUTx
> routine
> that will kill the log note and leading/trailing blanks.
>
> Now if the above were taken into account, code might look something like
> this:
>
> proc sql noprint ;
> create table dlm_model
> ( raw_term char (31) format=$31.
> , preferred_term char (36) format=$36.
> , wd_version char (04) format=$04.
> , term char (27) format=$04.
> , drug_code char (11) format=$11.
> , drug_name char (27) format=$27.
> ) ;
> quit ;
>
> %let dlm = ',' ;
>
> proc sql noprint ;
> select compress (name) into :dlm_vnames separated by &dlm
> from sashelp.vcolumn
> where libname = 'WORK' and memname = 'DLM_MODEL'
> ;
> select compress (name) into :vnames separated by " "
> from sashelp.vcolumn
> where libname = 'WORK' and memname = 'DLM_MODEL'
> ;
> quit ;
>
> data _null_ ;
> call symput ('_efierr_', "0") ;
> call symput ('_efirec_', "0") ;
>
> if 0 then set dlm_model ;
>
> file "c:\dt\test\xxx.csv" dlm = &dlm dsd dropover lrecl = 32767 ;
>
> put "&dlm_vnames" ;
>
> do _n_ = 1 by 1 until (eof) ;
> set whodrug_coded (keep = &vnames) end = eof ;
> put (_all_) (:) ;
> _efierr_ ++ _error_ ;
> end ;
>
> call symputx('_efierr_', ^^_efierr_) ;
> call symputx('_efirec_', _n_ ) ;
>
> stop ;
> run ;
>
> Store the DDL away in a separate library, then make changes only there,
> and
> leave SAS code alone. With 5 variables, you may not appreciate this modus
> operandi, but you quickly will if you have 200. In fact, most of the time
> DDL is
> supplied by the repository requirements. If this is not SAS, some tweak
> may
> be
> needed in the part pertaining to the formats and informats, but still all
> the
> work is done purely on the metadata side.
>
> Also, if you supply INformats with the model data set, you will be able,
> by
> replacing the PUT statement with the INPUT statement, to use essentially
> the
> same method to read from delimited files with hundreds of fields without
> going
> nuts about which variable follows which with which informat. Think it
> over...
>
>
> Kind regards
> ------------
> Paul Dorfman
> Jax, FL
> ------------
>
>
>
>
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> > Behalf Of Rao
> > Sent: Sunday, April 09, 2006 12:49 PM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: annoying error message in sas log
> >
> > Hi All
> >
> > I am executing a small code.
> >
> > libname sasdata "c:\dt\test";
> > proc export data=sasdata.whodrug_coded outfile ="c:\dt\test\xxx.csv"
> > dbms=csv replace;
> > run;
> >
> > But in sas log iam getting message as follows
> >
> >
> > libname sasdata "c:\dt\test";
> > 605 proc export data=sasdata.whodrug_coded outfile
> > ="c:\dt\test\xxx.csv"
> > 606 dbms=csv replace;
> > 607 run;
> > 608
> > /*********************************************************************
> > *
> > 609 * PRODUCT: SAS
> > 610 * VERSION: 8.2
> > 611 * CREATOR: External File Interface
> > 612 * DATE: 09APR06
> > 613 * DESC: Generated SAS Datastep Code
> > 614 * TEMPLATE SOURCE: (None Specified.)
> > 615
> > **************************************************************
> > *********/
> > 616 data _null_;
> > 617 set SASDATA.WHODRUG_CODED end=EFIEOD;
> > 618 %let _EFIERR_ = 0; /* set the ERROR detection macro
> > variable */
> > 619 %let _EFIREC_ = 0; /* clear export record count
> > macro variable
> > */
> > 620 file 'c:\dt\test\xxx.csv' delimiter=',' DSD DROPOVER
> > lrecl=32767;
> > 621 format Raw_term $31. ;
> > 622 format preferred_term $36. ;
> > 623 format WD_VERSION $4. ;
> > 624 format TERM $27. ;
> > 625 format DRUG_CODE $11. ;
> > 626 format DRUG_NAME $27. ;
> > 627 if _n_ = 1 then /* write column names */
> > 628 do;
> > 629 put
> > 630 'Raw_term'
> > 631 ','
> > 632 'preferred_term'
> > 633 ','
> > 634 'WD_VERSION'
> > 635 ','
> > 636 'TERM'
> > 637 ','
> > 638 'DRUG_CODE'
> > 639 ','
> > 640 'DRUG_NAME'
> > 641 ;
> > 642 end;
> > 643 do;
> > 644 EFIOUT + 1;
> > 645 put Raw_term $ @;
> > 646 put preferred_term $ @;
> > 647 put WD_VERSION $ @;
> > 648 put TERM $ @;
> > 649 put DRUG_CODE $ @;
> > 650 put DRUG_NAME $ ;
> > 651 ;
> > 652 end;
> > 653 if _ERROR_ then call symput('_EFIERR_',1); /* set
> > ERROR detection
> > macro variable */
> > 654 If EFIEOD then
> > 655 call symput('_EFIREC_',EFIOUT);
> > 656 run;
> > 12 records created in c:\dt\test\xxx.csv from
> > SASDATA.WHODRUG_CODED .
> >
> >
> >
> > If i can scan the sas log , Iam getting "ERROR" words like
> >
> > if _ERROR_ then call symput('_EFIERR_',1); /* set ERROR
> > detection macro variable */
> > 654 If EFIEOD then
> > 655 call symput('_EFIREC_',EFIOUT);
> >
> >
> > I donot want scan the commented "ERROR" in log .
> >
> >
> > If any one has idea please let me know.
> >
> > Thanks in advance.
> >
> > Rao
> >
>
|