|
I think you mix up with macro- and datastep-ifs.
E.g. flag is a variable you read in the datastep but the macro-ifs later in
your code are executed when the datstep is compiled, NOT when it executes.
Also Macro-language is 'simple' text-replacement, so in most cases it's
wrong to use '' around the values.
Use options mprint/mlogic/symbolgen to evaluate what code your macro
generates.
Eckhard
> -----Original Message-----
> From: Mayukh Dass [mailto:dass@UGA.EDU]
> Sent: Wednesday, May 05, 2004 8:09 AM
> To: SAS-L@AKH-WIEN.AC.AT
> Subject: problem with macro
>
>
> Hi,
>
> I have around 100-census dataset in text format. I need to do some
> analysis in all of them. In order to make work easy, I wrote a macro.
>
> %macro cens(filename=);
> data one;
> infile "C:\&filename" lrecl=180 pad missover obs=900;
> input ln $2-4 hn $6-9 fn $11-13 lname $15-28 fname $30-43 cage $45-48
> sex $51 occup $61-75 birth $86-96 remark $126-160 flag $6;
> %if flag ='1' %then output;
> %if flag ='2' %then output;
> %if flag ='3' %then output;
> %if flag ='4' %then output;
> %if flag ='5' %then output;
> %if flag ='6' %then output;
> %if flag ='7' %then output;
> %if flag ='8' %then output;
> %if flag ='9' %then output;
> /* %if flag in ('1', '2', '3','4','5','6','7','8','9') %then output;*/
> drop flag;
>
> data two;
> set one;
> /* Here, we are trying to convert ages that are less than 1 year to 1
> year*/
> cagep=compress(cage,'/');
> %if cagep >100 %then cage='1';
> %else cage=cagep;
> /* Here, we are trying to convert ages that are U or 2* to .*/
> %if cage='U' or cage='2*' %then cage=.;
> drop cagep;
>
> data three;
> set two;
> /* here we are converting the string to integer data type for the
> variable age*/
> age=input(cage,2.);
> drop cage;
> /* Here we are trying to delete all the records whose sex is not
> assigned as 'M' or 'F'*/
> %if sex ne 'F'and sex ne'M' %then delete;
> proc print;run;
> quit;
>
> %mend cens;
>
> %cens(filename=aa1.txt);
> run;
>
> but I am getting a LOG output as
>
> 217 %macro cens(filename=);
> 218 data one;
> 219 infile "C:\Documents and Settings\Mayukh Dass\My
> Documents\iFolder\BILLARD\&filename" lrecl=180 pad missover obs=900;
>
> 220 input ln $2-4 hn $6-9 fn $11-13 lname $15-28 fname $30-43 cage
> $45-48
> 221 sex $51 occup $61-75 birth $86-96 remark $126-160 flag $6;
> 222 %if flag ='1' %then output;
> 223 %if flag ='2' %then output;
> 224 %if flag ='3' %then output;
> 225 %if flag ='4' %then output;
> 226 %if flag ='5' %then output;
> 227 %if flag ='6' %then output;
> 228 %if flag ='7' %then output;
> 229 %if flag ='8' %then output;
> 230 %if flag ='9' %then output;
> 231 /* %if flag in ('1', '2', '3','4','5','6','7','8','9') %then
> output;*/
> 232 drop flag;
> 233
> 234 data two;
> 235 set one;
> 236 /* Here, we are trying to convert ages that are less
> than 1 year to
> 1 year*/
>
> 237 cagep=compress(cage,'/');
> 238 %if cagep >100 %then cage='1';
> 239 %else cage=cagep;
> 240 /* Here, we are trying to convert ages that are U or 2* to .*/
> 241 %if cage='U' or cage='2*' %then cage=.;
> 242 drop cagep;
> 243
> 244 data three;
> 245 set two;
> 246 /* here we are converting the string to integer data type for the
> variable age*/
>
> 247 age=input(cage,2.);
> 248 drop cage;
> 249 /* Here we are trying to delete all the records whose sex is not
> assigned as 'M' or 'F'*/
>
> 250 %if sex ne 'F'and sex ne'M' %then delete;
> 251 proc print;run;
> 252 quit;
> 253
> 254 %mend cens;
> 255
> 256 %cens(filename=aa1.txt);
>
> NOTE: The infile "C:\aa1.txt" is:
> File Name=C:\aa1.txt,
> RECFM=V,LRECL=180
>
> NOTE: 814 records were read from the infile "C:\aa1.txt".
> The minimum record length was 0.
> The maximum record length was 176.
> NOTE: The data set WORK.ONE has 814 observations and 10 variables.
> NOTE: DATA statement used:
> real time 0.07 seconds
> cpu time 0.01 seconds
>
>
> NOTE: Line generated by the invoked macro "CENS".
> 9 drop cagep;
> ----
> 79
>
> ERROR 79-322: Expecting a ;.
>
> NOTE: The SAS System stopped processing this step because of errors.
> WARNING: The data set WORK.TWO may be incomplete. When this step was
> stopped there were 0 observations and 10 variables.
> WARNING: Data set WORK.TWO was not replaced because this step was
> stopped.
> NOTE: DATA statement used:
> real time 0.01 seconds
> cpu time 0.01 seconds
>
>
>
> NOTE: Line generated by the invoked macro "CENS".
> 13 proc print;run;
> ----
> 79
> 76
>
> ERROR 79-322: Expecting a ;.
>
> ERROR 76-322: Syntax error, statement will be ignored.
>
> NOTE: The SAS System stopped processing this step because of errors.
> WARNING: The data set WORK.THREE may be incomplete. When
> this step was
> stopped there were 0 observations and 10 variables.
> WARNING: Data set WORK.THREE was not replaced because this step was
> stopped.
> NOTE: DATA statement used:
> real time 0.03 seconds
> cpu time 0.01 seconds
>
>
>
> 257 run;
>
>
>
> It will be great if you can show me where I am making the mistake.
> Thanks in advance.
>
> Mayukh
>
|