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 (January 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 20 Jan 2005 18:44:12 -0500
Reply-To:     "Miller, Jeremy T." <zyp9@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Miller, Jeremy T." <zyp9@CDC.GOV>
Subject:      macro logic
Content-Type: text/plain; charset="us-ascii"

I'm having some difficulty figuring out why my code is "working," but not really working.

I have to read in 20 flat files. The problem is that whoever did the survey changed things from year to year without thinking of the consequences for people who have to use the data. Anyway, so I have a number of different input statements that need to be read according to the year. Each text file is the input statement.

My specific problem is that the conditional logic is not working--only the first input is read because the test is always returned as 'TRUE.'

Thanks for any help.

My macro:

%MACRO readin(first,last); %do i=&first %to &last; data _null_;set flat2; call symput('dsn', trim(left(var_&i))); /* Calls the name of the flat file */ run;

%let yr = %substr(&dsn,7); /* Gets year */

data &dsn ; INFILE "Q:\Projects\Mortality\Flat\&dsn" LRECL=400 RECFM=V TRUNCOVER ; %if 1983 <= &yr <=1987 %then %include "Q:\Projects\HAV_mort_83_02\Code\Inputs\in_79_88.txt"; %else %if &yr = 1988 %then %include "Q:\Projects\HAV_mort_83_02\Code\Inputs\in_88.txt"; %else %if 1989 <= &yr <=1991 %then %include "Q:\Projects\HAV_mort_83_02\Code\Inputs\in_89_91.txt"; %else %if 1992 <= &yr <=1995 %then %include "Q:\Projects\HAV_mort_83_02\Code\Inputs\in_92_95.txt"; %else %if 1996 <= &yr <=1998 %then %include "Q:\Projects\HAV_mort_83_02\Code\Inputs\in_96_98.txt"; %else %include "Q:\Projects\HAV_mort_83_02\Code\Inputs\in_99.txt"; ; run;

%end; %MEND readin; /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 */

%readin(1,20)

One part of the output:

MLOGIC(READIN): %LET (variable name is YR) SYMBOLGEN: Macro variable DSN resolves to MCMORT2001 SYMBOLGEN: Macro variable DSN resolves to MCMORT2001 MPRINT(READIN): data MCMORT2001 ; SYMBOLGEN: Macro variable DSN resolves to MCMORT2001 MPRINT(READIN): INFILE "Q:\Projects\Mortality\Flat\MCMORT2001" LRECL=400 RECFM=V TRUNCOVER ; SYMBOLGEN: Macro variable YR resolves to 2001 MLOGIC(READIN): %IF condition 1983 <= &yr <=1987 is TRUE <<<-----PROBLEM HERE MPRINT(READIN): input @39 POP_RES $CHAR1. @55 DTH_MON 2. @57 DTH_DAY 2. @1 DTH_YR 2. @59 GENDER 1. @60 RACE1 2. @64 AGE_fl 1. @65 AGE_un 2. @69 AGE_GRP 2. @75 HOSP_STA1 1. @77 MAR_STAT 1. @84 AUTOP 1. @85 BUSN 3. @88 US_JOB 3. @26 REG_OCC 1. @119 ST_OCC 2. @121 CNTY_OCC $CHAR3. @41 REG_RES 1. @124 ST_RES 2. @126 CNTY_RES $CHAR3. @141 WHR_DIE 1. @142 U_CODE $CHAR4. @164 EA_CD1 $CHAR4. @171 EA_CD2 $CHAR4. @178 EA_CD3 $CHAR4. @185 EA_CD4 $CHAR4. @192 EA_CD5 $CHAR4. @199 EA_CD6 $CHAR4. @206 EA_CD7 $CHAR4. @213 EA_CD8 $CHAR4. @220 EA_CD9 $CHAR4. @227 EA_CD10 $CHAR4. @234 EA_CD11 $CHAR4. @241 EA_CD12 $CHAR4. @248 EA_CD13 $CHAR4. @255 EA_CD14 $CHAR4. @262 EA_CD15 $CHAR4. @269 EA_CD16 $CHAR4. @276 EA_CD17 $CHAR4. @283 EA_CD18 $CHAR4. @290 EA_CD19 $CHAR4. @297 EA_CD20 $CHAR4. @341 RA_CD1 $CHAR4. @346 RA_CD2 $CHAR4. @351 RA_CD3 $CHAR4. @356 RA_CD4 $CHAR4. @361 RA_CD5 $CHAR4. @366 RA_CD6 $CHAR4. @371 RA_CD7 $CHAR4. @376 RA_CD8 $CHAR4. @381 RA_CD9 $CHAR4. @386 RA_CD10 $CHAR4. @391 RA_CD11 $CHAR4. @396 RA_CD12 $CHAR4. @401 RA_CD13 $CHAR4. @406 RA_CD14 $CHAR4. @411 RA_CD15 $CHAR4. @416 RA_CD16 $CHAR4. @421 RA_CD17 $CHAR4. @426 RA_CD18 $CHAR4. @431 RA_CD19 $CHAR4. @436 RA_CD20 $CHAR4. ; MPRINT(READIN): if dth_day >31 or dth_day = . then dth_day = 15; MPRINT(READIN): DT_DTH = mdy(dth_mon,dth_day,dth_yr); MPRINT(READIN): if age_fl=0 then AGE = age_un; MPRINT(READIN): else if age_fl=1 then age = age_un+100; MPRINT(READIN): else if age_fl=2 then age = age_un/12; MPRINT(READIN): else if age_fl=3 then age = age_un/52; MPRINT(READIN): else if age_fl=4 then age = age_un/364.25; MPRINT(READIN): else if age_fl=5 then age = age_un/(364.25*24); MPRINT(READIN): else if age_fl=6 then age = age_un/(364.25*24*60); MPRINT(READIN): else if age_fl=9 then age =.; MPRINT(READIN): FLAG = 0; MPRINT(READIN): array _ucd{*} u_code--ra_cd20; MPRINT(READIN): do j = 1 to dim(_ucd); SYMBOLGEN: Macro variable CODES2 resolves to '0700','0701','B15','B150','B159' MPRINT(READIN): if _ucd{j} IN('0700','0701','B15','B150','B159') then flag = 1; MPRINT(READIN): end; MPRINT(READIN): if flag = 0 then delete; MPRINT(READIN): drop age_fl age_un j flag; MPRINT(READIN): format dt_dth mmddyy10.; MPRINT(READIN): run;

NOTE: The infile "Q:\Projects\Mortality\Flat\MCMORT2001" is: File Name=Q:\Projects\Mortality\Flat\MCMORT2001, RECFM=V,LRECL=400

NOTE: 2419960 records were read from the infile "Q:\Projects\Mortality\Flat\MCMORT2001". The minimum record length was 400. The maximum record length was 400. One or more lines were truncated. NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 2419960 at 187:74 NOTE: The data set WORK.MCMORT2001 has 179 observations and 62 variables. NOTE: DATA statement used (Total process time): real time 2:12.20 user cpu time 1:39.95 system cpu time 1.62 seconds Memory 212k


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