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 (May 2002, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 28 May 2002 11:34:40 -0400
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: Problem with %if
Comments: cc: Randy Herbison <RandyHerbison@WESTAT.com>
Content-Type: text/plain; charset="iso-8859-1"

Much to my horror Randy Herbison <randyHerbison@westat.com> pointed out to me that there were mistakes in the code that I wrote in replying to Sheila Whitelaw's <sw75@BOXFROG.COM> question about a %IF. Unfortunately, I included the code before testing rather than after. I thought I had replaced the untested code, but apparently not. In case anyone else is curious, here is the tested code.

%macro Random ( outroot = test /* root for output data sets */ , split= yes /* one file or many */ , nobs = 10 /* num obs in total */ , nsets = 3 /* determins split var */ , debug = yes /* are prints wanted? */ ) ; %local i ; /* looping variable */ %let split = %upcase ( &split ) ; %let debug = %upcase ( &debug ) ;

data %if &split = YES %then %do ; %do i = 1 %to &nsets ; &outroot&i %end ; %end ; %else &outroot ; ; drop j ; do j=1 to 10; x=ranuni(0); y=mod(int(10*x),&nsets);

%if &split = YES %then %do ; select ( y ) ; when (0) output &outroot&nsets ; %do i = 1 %to &nsets - 1 ; when (&i) output &outroot&i ; %end ; otherwise error ; end ; %end ; %else %do ; output &outroot ; %end ; end ; run;

%if &debug = YES %then %do ; %if &split = YES %then %do ; %do i=1 %to &nsets ; proc print data=&outroot&i; title2 "&outroot&i"; run; %end ; %end ; %else %do ; proc print data=&outroot&i; title2 "&outroot&i"; run; %end ; %end; %mend random ;

options mprint ; %random()

An interesting exercise in studying how names influence the difficulty of code can be obtained by assuming the output data set name is &OUTROOT.1 when only one data set is requested.

IanWhitock@westat.com


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