Date: Thu, 2 Jan 1997 17:48:32 EDT
Reply-To: hermans1@WESTATPO.WESTAT.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Sig Hermansen <hermans1@WESTATPO.WESTAT.COM>
Subject: Help with Macro ... sort order of key variables
You may have to rethink the design of the program. Even if you
correct all of the syntax and runtime errors, it may prove too
complicated to explain how and why it works. If you define each major
step in a Macro and focus on the contents of the datasets or
macrovariables read and produced by each step, you will reduce the
main program to one page. You can then examine each step to make sure
that the incoming and outgoing variables have the correct definition
and that rows (obs, records) have the correct order for merges or
summaries.
So far as I can tell, the "not properly sorted" runtime error occurs
because the samestep Macro orders the dataset plan differently than
specified in the BY statement of the MERGE of plan, county, and state.
The "variable ... is uninitialized" warnings arise because you named
macrovariables in a LENGTH statement. SAS creates columns in the
output dataset for these supposed data step variables, but they remain
missing. SAS does not confuse macrovariable names with data step
variable names (as I for have at times!).
PROC SQL does not require that you order the data to do the
equivalents of MERGES and summaries. For that reason and others I
almost always use SQL joins instead of datastep MERGES to link
datasets on key values.
--------------- Excerpt from original message -----------------------
<Date: Thu, 2 Jan 1997 14:36:13 EST
<From: Suhua Hu <sxh04@HEALTH.STATE.NY.US>
<Subject: Need Help with My Macro Program
...........................................................
<625 %macro samestep (outname=state, inname=elig, type1=0, type2=2,
<626 type3=3, byvar=);
..........................................................
<634 proc sort;
<635 by &byvar sex agecat;
<636 run;
<637 %mend samestep;
...............................................................
<714 data final (drop=ctycode _type_);
<715 merge plan county (rename=(qn=c7 yn=c8 qmm=c9 ymm=c10))
<716 state (rename=(qn=c11 yn=c12 qmm=c13 ymm=c14));
<717 by agecat sex;
<718
..........................................
<NOTE: VARIABLE C_ID IS UNINITIALIZED.
<NOTE: VARIABLE C_NAME IS UNINITIALIZED.
<NOTE: VARIABLE P_NAME IS UNINITIALIZED.
<ERROR: BY VARIABLES ARE NOT PROPERLY SORTED ON DATA SET WORK.PLAN.
<ERROR: BY VARIABLES ARE NOT PROPERLY SORTED ON DATA SET WORK.PLAN.
<ERROR: BY VARIABLES ARE NOT PROPERLY SORTED ON DATA SET WORK.PLAN.