LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (October 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 13 Oct 2003 09:30:14 -0400
Reply-To:   Ed Heaton <EdHeaton@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Ed Heaton <EdHeaton@WESTAT.COM>
Subject:   RE: Réf. : macro error
Comments:   To: "jacques.lanoue@DESJARDINS.COM" <jacques.lanoue@DESJARDINS.COM>
Content-Type:   text/plain; charset="iso-8859-1"

Jacques,

A couple of simple changes will make your code even more efficient.

%macro n_obs(ds); %global N_OBS; data _null_; call symput('n_obs',N_OBS); stop; set &ds(drop=_all_) Nobs=N_OBS; run; %mend;

This avoids two things. There is no reason to build the PDV (program data vector) for all of your variables just to count the observations. Hence the DROP=_ALL_ data set option. And there is no reason to read any of the data, even the first observation. You only need to read the header and that happens at compile time. So let's stop the step after executing the CALL SYMPUT statement.

The DROP=_ALL_ data set option reduced the run time of the following from 0.91 seconds to 0.06 seconds. To show the difference, I made a data set with 32,000 variables.

Now, I tend to try to avoid defining global macro variables in a local environment. So you could modify the code some more with...

%macro n_obs( data=&sysLast , mVar=nObs ); data _null_; call symput("&mVar",put(N_OBS,best12.-L)); stop; set &data(drop=_all_) Nobs=N_OBS; run; %put &&mVar ; %mend n_obs ;

data test; Array k [32000] ; do i=1 to 5; Do j=1 to 32000 ; k[j] = j ; End ; output; end; run; %global nObs ; %n_obs( data=test , mVar=nObs ) %put nObs=&nObs ;

Ed

Edward Heaton, Senior Systems Analyst, Westat (An Employee-Owned Research Corporation), 1600 Research Boulevard, Room RW-3541, Rockville, MD 20850-3195 Voice: (301) 610-4818 Fax: (301) 610-5128 mailto:EdHeaton@westat.com http://www.westat.com

-----Original Message----- From: Jacques Lanoue [mailto:jacques.lanoue@DESJARDINS.COM] Sent: Wednesday, October 08, 2003 4:24 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Réf. : macro error

There are many ways to find out how many obs in a dataset. Try this one, I think it is more efficient.

%macro n_obs(ds); %global N_OBS; data _null_; set &ds Nobs=N_OBS; call symput('n_obs',N_OBS); stop; run; %mend;

data test; do i=1 to 5; output; end; run; %n_obs(test);

%put _all_;

Jacques Lanoue An other SAS Guy

Rune Runnestoe <rune@FASTLANE.NO>@LISTSERV.UGA.EDU> on 2003-10-08 16:12:15

Veuillez répondre à Rune Runnestoe <rune@FASTLANE.NO>

Envoyé par : "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>

Pour : SAS-L@LISTSERV.UGA.EDU cc : Objet : macro error

The code goes like this:

%macro count_datafiles; proc sql noprint; select count(*) into :ant_arkiv from &bibl..arkiv;

select count(*) into :ant_sak from &bibl..sak;

select count(*) into :ant_dok from &bibl..dok; quit; %mend;

%macro test_datafiles; *Macro to test the number of records in the datasets;

%count_datafiles; data &bibl..kompl_antall; ARKIV = &ant_arkiv; SAK = &ant_sak; DOK = &ant_dok; run; %mend;

%test_datafiles;

--------------------------------------------- The message from the log is as follows:

MPRINT(COUNT_DATAFILES): proc sql noprint; SYMBOLGEN: Macro variable BIBL resolves to SAHA8800 MPRINT(COUNT_DATAFILES): select count(*) into :ant_arkiv from SAHA8800.arkiv; SYMBOLGEN: Macro variable BIBL resolves to SAHA8800 MPRINT(COUNT_DATAFILES): select count(*) into :ant_sak from SAHA8800.sak; SYMBOLGEN: Macro variable BIBL resolves to SAHA8800 MPRINT(COUNT_DATAFILES): select count(*) into :ant_dok from SAHA8800.dok; MPRINT(COUNT_DATAFILES): quit; NOTE: PROCEDURE SQL used: real time 0.42 seconds cpu time 0.08 seconds

MLOGIC(COUNT_DATAFILES): Ending execution. MPRINT(TEST_DATAFILES): ; SYMBOLGEN: Macro variable BIBL resolves to SAHA8800 WARNING: The Base Product product with which DATASTEP is associated will expire within 30 days. Please contact your SAS installation representative to have it renewed. MPRINT(TEST_DATAFILES): data SAHA8800.kompl_antall; SYMBOLGEN: Macro variable ANT_ARKIV resolves to 168 MPRINT(TEST_DATAFILES): ARKIV = 168; SYMBOLGEN: Macro variable ANT_SAK resolves to 20385 22: LINE and COLUMN cannot be determined. NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN where the error has occurred. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. MPRINT(TEST_DATAFILES): SAK = 20385; WARNING: Apparent symbolic reference ANT_DOK not resolved. MPRINT(TEST_DATAFILES): DOK = &ant_dok; MPRINT(TEST_DATAFILES): run;

NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set SAHA8800.KOMPL_ANTALL may be incomplete. When this step was stopped there were 0 observations and 4 variables. WARNING: Data set SAHA8800.KOMPL_ANTALL was not replaced because this step was stopped. NOTE: DATA statement used: real time 0.00 seconds cpu time 0.00 seconds

MLOGIC(TEST_DATAFILES): Ending execution.

---------------------------------------------

What is wrong with my code ?

Regards Rune Runnestoe


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