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 (January 2000, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 11 Jan 2000 17:38:48 -0500
Reply-To:   andrea.wainwright@CAPITALONE.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Andrea Wainwright <andrea.wainwright@CAPITALONE.COM>
Subject:   if-then statements to turn code on/off
Comments:   To: SAS-L@LISTSERV.VT.EDU
Content-Type:   text/plain; charset="US-ASCII"

I have been banging my head on this for a while and have decided it is time to get this figured out. I have a long program with sections of code that I may or may not need to run based on the need. I have included the following:

%LET TESTOBS = 0; * 0 MEANS USE ALL CASES, # * * MEANS TO ONLY READ # CASES*;

%LET CHECK5K = 1; * SET TO 1 IF DOING 5K CHECK*;

%LET COMPARE = 1; * SET COMPARE TO 1 IF YOU * * WANT TO DO COMPARISONS *;

Then through out the code there are sections such as:

DATA SAMPLIB.MYDATA; INFILE FLAT TRUNCOVER; /**FLAT is defined in JCL and works fine**/ IF &TESTOBS>0 THEN DO; /* THIS STATEMENT INSTRUCTS THE */ IF _N_=&TESTOBS THEN STOP; /* THE DATASTEP TO PROCESS THE */ END; /* FIRST &TESTOBS OBSERVATIONS, */ /* IF &TESTOBS>0. */ INPUT @1234 yadda1 1. yadda2 2. yadda3 3. @;

IF &CHECK5K=1 THEN DO; INPUT @2345 ABC 2. DEF 2. @; END; OUTPUT SAMPLIB.MYDATA; RUN;

But when I follow that with the following section of code SAS starts yelling.

IF &CHECK5K=1 THEN DO; PROC FREQ DATA=SAMPLIB.MYDATA; TABLES ABC*DEF/MISSING LIST; RUN; END;

The log looks like:

1979 IF &CHECK5K=1 THEN DO; __ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 1980 PROC FREQ DATA=SAMPLIB.MYDATA; 1981 TABLES ABC*DEF/MISSING LIST; 1982 RUN; NOTE: SAS set option OBS=0 and will continue to check statements. This may cause NOTE: No observations in data set. NOTE: The PROCEDURE FREQ used 0.00 CPU seconds and 5756K. 1983 END; ___ 180 ERROR 180-322: Statement is not valid or it is used out of proper order.

Now I know there is a difference between if-then and %if-%then, but I am not using this in a macro, and the only examples I can find of %if-%then are in macros.

I understand the if-then works on an individual observation, and that is why it works inside the data set to turn the code on and off, but not outside the data step. How do I accomplish this outside the data step?

Thank you

Andrea Wainwright


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