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 (September 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 1 Sep 2006 20:45:48 -0700
Reply-To:     toby989@HOTPOP.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby989@HOTPOP.COM
Subject:      Re: exist function question
Comments: To: sas-l@uga.edu
In-Reply-To:  <BAY123-F72DB11D89BE625F480FB2DE3C0@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Toby

The c dataset looks like:

_name_ f1 f2 f3 q01 1 0 0 q02 1 0 0 q07 1 0 0 q03 0 1 0 q04 0 1 0 q06 0 1 0 q05 0 0 1

and the q's are variables in the ps2004ms dataset.

And my macro that now works only partially looks like:

%macro efamac(n=,m=,p=,r=,i=); %do ix=1 %to &n; proc sql; select trim(left(_name_)) into :lista separated by ' ' from c where f&ix=1; quit; proc corr data=psdata.ps2004ms(where=(id<200 and id not in (49, 109) and half=0)) alpha nocorr nosimple outp=outcal(where=(_type_='STDALPHA')); var &lista ; run; proc transpose data=outcal(drop=_type_ _name_) out=outcal(drop=_name_); run; proc sql; insert into outc set _type_='STAT', _name_='STDALPHA', &m&n&p&r=(select distinct col1 from outcal); quit; %end; data y; %sysfunc(ifc(&i=1, set outc, merge y outc)); attrib _all_ label=''; run; %mend;

data _null_; i=1; do n=' 3'; do m='a'; do p='a'; do r='n', 'q', 'v'; call execute('%efamac(n='||n||',m='||m||',p='||p||',r='||r||',i='||i||')'); i=i+1; end; end; end; end; run;

Some of the log file: The issue is where my macro variable suddenly becomes listed twice, and three times, and 4 times if I my 'to' value of the loop would be 4 and so on.

trim(left(_name_)) into :lista separated by ' ' from c where f3=1; 17 + quit; NOTE: PROCEDURE SQL used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

17 + proc corr data=psdata.ps2004ms(where=(id<200 and id not in (49, 109) and half=0)) 18 + alpha nocorr nosimple outp=outcal(where=(_type_='STDALPHA')); var &lista &lista &lista ; run; proc transpose data=outcal(drop=_type_ _name_) out=outcal(drop=_name_); run; proc sql; insert into outc set _type_='STAT', _name_='STDALPHA', a3an=(select

WARNING: Variable q10 already exists on file WORK.OUTCAL. WARNING: Variable q18 already exists on file WORK.OUTCAL. WARNING: Variable q20 already exists on file WORK.OUTCAL. WARNING: Variable q23 already exists on file WORK.OUTCAL. WARNING: Variable q26 already exists on file WORK.OUTCAL. WARNING: Variable q31 already exists on file WORK.OUTCAL. WARNING: Variable q10 already exists on file WORK.OUTCAL. WARNING: Variable q18 already exists on file WORK.OUTCAL. WARNING: Variable q20 already exists on file WORK.OUTCAL. WARNING: Variable q23 already exists on file WORK.OUTCAL. WARNING: Variable q26 already exists on file WORK.OUTCAL. WARNING: Variable q31 already exists on file WORK.OUTCAL. WARNING: Cronbach's Alpha has been computed with missing values present. Using the NOMISS option is recommended. NOTE: The data set WORK.OUTCAL has 1 observations and 8 variables. NOTE: PROCEDURE CORR used (Total process time): real time 0.15 seconds cpu time 0.15 seconds

NOTE: There were 1 observations read from the data set WORK.OUTCAL. NOTE: The data set WORK.OUTCAL has 6 observations and 1 variables. NOTE: PROCEDURE TRANSPOSE used (Total process time): real time 0.03 seconds cpu time 0.03 seconds

19 + distinct col1 from outcal); NOTE: 1 row was inserted into WORK.OUTC.

19 + quit; NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds

19 + data y; set outc; attrib _all_ label=''; run;

NOTE: There were 37 observations read from the data set WORK.OUTC. NOTE: The data set WORK.Y has 37 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds

Toby

toby dunn wrote: > Toby , > > I would look at your macro code. I tested the code out in two different > macro set ups and it always seems to work just fine for me. > > > > 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: toby989@HOTPOP.COM > Reply-To: toby989@HOTPOP.COM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: exist function question > Date: Thu, 31 Aug 2006 19:47:57 -0700 > > Toby > > The error, I know, just for testing purposes, to see what the > sysfunc(exist(y)) > returns. > > Your example works on my side too. > > .... > > Can it be, since my thing is part of a macro, that when I compile the macro > the > sysfuncs are evaluated and the datastep is created/set in stone. The > datastep is > not dynamically recreated everytime I call the macro......tested it, seems > not > to be the case. > > Toby > > > > toby dunn wrote: > >>Toby , >> >>data y ; >>%sysfunc(exist(y)) ; >>run ; >> >> >>Is always gonna give you an error, why well consider what the resulting >>data >>step code will look like: >> >>If Data Set Y exists: >> >>Data Y ; >>1 >>Run ; >> >>And If it doesnt exists: >> >>Data Y ; >>0 >>Run ; >> >>Either way you just have a number sitting out there all alone in the night >>with no context to help SAS figure out what you are doing. >> >> >> >>data y; >>%sysfunc(ifc(%sysfunc(exist(y)),merge y outcfa,set outcfa)); >>run; >> >>Works just as Howard advertised it too work just read your log: >> >>NOTE: There were 34 observations read from the data set WORK.Y. >>NOTE: There were 34 observations read from the data set WORK.OUTCFA. >>NOTE: The data set WORK.Y has 34 observations and 3 variables. >>NOTE: DATA statement used (Total process time): >> real time 0.01 seconds >> cpu time 0.01 seconds >> >>Notice that it found data set Y and reads observation from both and merges >>them however you have no by statement. Which may or may not cause you >>problems. >> >> >>Data Y ; >>X = 'A' ; >>Y = '1' ; >>Output ; >> >>X = 'B' ; >>Y = '2' ; >>Output ; >> >>X = 'C' ; >>Y = '3' ; >>Output ; >> >>Run ; >> >> >>Data X ; >>X = 'A' ; >>Z = '999' ; >>Output ; >> >>X = 'C' ; >>Z = '999' ; >>Output ; >> >>Run ; >> >> >>Data Y ; >>%SysFunc( IfC( %SysFunc( Exist( Y ) ) , Merge Y X %Str( ; ) By X %Str( ; ) >>, >>Set X %Str( ; ) ) ) ; >>Run ; >> >>Proc Print >>Data = Y ; >>Run ; >> >> >> >>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: toby989@HOTPOP.COM >>Reply-To: toby989@HOTPOP.COM >>To: SAS-L@LISTSERV.UGA.EDU >>Subject: Re: exist function question >>Date: Thu, 31 Aug 2006 16:11:13 -0700 >> >>Howard Schreier <hs AT dc-sug DOT org> wrote: >> >> >>>On Wed, 30 Aug 2006 14:40:13 -0700, toby989@HOTPOP.COM wrote: >>> >>> >>> >>> >>>>do I miss somehting here? >>> >>> >>>Yes, if you were expecting a different outcome. >>> >>>Remember that the DATA step examines the headers of all input data sets >>>(those named on SET, MERGE, UPDATE, and MODIFY statements) at compile >>>time. >>> >>>Try this: >>> >>> data y; >>> %sysfunc(ifc(%sysfunc(exist(y)),merge y outcfa,set outcfa)); >>> run; >>> >> >>Thank you. This is very helpful. the %sysfunc(exist(y)) returns '1' as can >>be >>seen below. But the %sysfunc(ifc(...)) does not take it somehow. >> >>76 data y; >>77 %sysfunc(exist(y)); >>NOTE: Line generated by the macro function "SYSFUNC". >>1 1 >> - >> 180 >>ERROR 180-322: Statement is not valid or it is used out of proper order. >> >>78 run; >> >>NOTE: The SAS System stopped processing this step because of errors. >>WARNING: The data set WORK.Y may be incomplete. When this step was stopped >>there were 0 >> observations and 0 variables. >>WARNING: Data set WORK.Y was not replaced because this step was stopped. >>NOTE: DATA statement used (Total process time): >> real time 0.01 seconds >> cpu time 0.01 seconds >> >> >> >> >>It only performs the 'set' command. >> >>79 data y; >>80 %sysfunc(ifc(%sysfunc(exist(y)),merge y outcfa,set outcfa)); >>81 run; >> >>NOTE: There were 34 observations read from the data set WORK.Y. >>NOTE: There were 34 observations read from the data set WORK.OUTCFA. >>NOTE: The data set WORK.Y has 34 observations and 3 variables. >>NOTE: DATA statement used (Total process time): >> real time 0.01 seconds >> cpu time 0.01 seconds >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>>>data y; if (exist('y')) then merge y outcfa; else set outcfa; run; >>>>ERROR: File WORK.Y.DATA does not exist. >>>> >>>>NOTE: The SAS System stopped processing this step because of errors. >>>>WARNING: The data set WORK.Y may be incomplete. When this step was >>>>stopped >>>>there were 0 >>>> observations and 3 variables. >>>>NOTE: DATA statement used (Total process time): >>>> real time 0.01 seconds >>>> cpu time 0.01 seconds


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