The line
-------------------------------
%let dsid = %sysfunc(open(Healthpartners12,is));
--------------------------------
Opens the dataset and sets the macro variable dsid to a numeric value referencing that open file.
The lines
--------------------------------
%let rc = %sysfunc(close(&dsid));
----------------------------------
Close that open file makeing the value of dsid unusable. What you need to do is either ad another open statement before you start the part that checks mg, or move the close statments so that they occur after you are done with the dsid reference. The trick is that it must be closed before you execute the dataset because the open statement locks the dataset. I think the simpliest approach would be to test the two variables and save the results in macro varaibles, then close the open dataset before starting to write the DATA step. The added advantage is that both conversions can be handled in a single datastep. Something like this.
---------------------------------------------
data Healthpartners12;
x = 1;
zip = '98501';
mg=60.01;
run;
%macro changeZip;
%let dsid = %sysfunc(open(Healthpartners12,is));
%let ChangeZip = False;
%let ChangeMG = False;
%if %sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,zip)))) = N %then %let ChangeZip = True;
%if %sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,mg)))) = C %then %let ChangeMG = True;
%let rc = %sysfunc(close(&dsid));
%if &ChangeZip = True or &ChangeMG = True %then %do;
data Healthpartners12;
set Healthpartners12(%if &ChangeZip = True %then %do;
rename = (ZIP = ZIpUnkn)
%end;
%if &ChangeMG = True %then %do;
rename = (mg = mgUnkn)
%end;
);
%if &ChangeZip = True %then %do;
drop = zipUnkn;
length zip $5;
zip=strip(put(zipUnkn,z5.));
%end;
%if &ChangeMG = True %then %do;
drop = mgUnkn;
length mg 8;
mg=input(mgUnkn,??best12.);
%end;
run;
%end;
%mend;
options mprint;
%changeZip;
-------------------------------------------
Message was edited by: Curtis Mack