BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zaldarsa
Obsidian | Level 7

Hello!

When I try to run the array below, the following message appears in my log: NOTE: Variable l is uninitialized.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the
BY expression is missing, zero, or invalid. However, I can't figure out what is wrong with the code. Thank you all in advance for your help!

data diet6;
set diet6;
array dbp  dbp0 dbp7 dbp20;
array sbp  sbp0 sbp7 sbp20;
array  htn htn0 htn7 htn20;
do i=1 to dim(dbp);
if dbp(i)ge 90 and sbp(i) ge 140 then htn(i)= "1";
else htn(i)= "0";
end;
array weightkg weightkg0 weightkg7 weightkg20;
array heightm  heightm0 heightm7  heightm20;
array bmi bmi0 bmi7 bmi20;
do i=l to dim(weightkg);
bmi(i)= (weightkg(i))/(heightm(i))**2;
end;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Read your code and read the log.

If you look not so closely at the highlighted code below you will see that one of the characters is numeral for one, the other is a letter , lower case L. So unless you have a numeric variable named L that has a value inside the valid range for the array using that part of the loop, it starts i with an invalid value. If you do not have a variable L the first value of I is missing. 1 l  0 O  , one L, zero capital O are two ancient and common coding problems.

data diet6;
set diet6;
array dbp  dbp0 dbp7 dbp20;
array sbp  sbp0 sbp7 sbp20;
array  htn htn0 htn7 htn20;
do i=1 to dim(dbp);
if dbp(i)ge 90 and sbp(i) ge 140 then htn(i)= "1";
else htn(i)= "0";
end;
array weightkg weightkg0 weightkg7 weightkg20;
array heightm  heightm0 heightm7  heightm20;
array bmi bmi0 bmi7 bmi20;
do i=l to dim(weightkg);
bmi(i)= (weightkg(i))/(heightm(i))**2;
end;

 

View solution in original post

8 REPLIES 8
zaldarsa
Obsidian | Level 7

Sure thing. 

NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
12:39 13:6
NOTE: Variable l is uninitialized.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the
BY expression is missing, zero, or invalid.
CENTER=1 ID=100061300991 age0=20 RACE=4 SEX=1 age7=28 age20=42 age25=46 age30=51 education0=2
education7=2 income7=6 education20=2 income20=10 smoke0=2 smoke7=2 smoke20=2 pact0=351 pact7=322
pact20=462 heightcm0=187 weightlb0=182 wasitcm0=76.5 heightcm7=188.5 weightlb7=218 waistcm7=89.5
heightcm20=189.5 weightlb20=233 waistcm20=96.75 sbp0=109 dbp0=64 sbp7=120 dbp7=78 sbp20=173
dbp20=109 trig0=45 hdl0=54 ldl0=101 hdl7=56 ldl7=131 trig7=69 trig20=220 ldl20=132 hdl20=52
glucose0=82 glucose7=81.523838915 glucose20=117.98560569 A07MLALC=7.1571428571 D07MLALC=36.81
G07MLALC=22.495714286 flag25=0 flag30=1 monosat0=1.2866878692 monosat7=1.0806127574
monosat20=1.2572706935 ICV25=. totalbrain25=. gm25=. frontalgm25=. occipitalgm25=. parietalgm25=.
temporalgm25=. wm25=. frontalwm25=. occipitalwm25=. parietalwm25=. temporalwm25=. abnormalwm25=.
hippocampus25=. amygdala25=. entorarea25=. poscingyrus25=. precuneus25=. ICV30=1660242
totalbrain30=1255052 gm30=640126 frontalgm30=178869 occipitalgm30=70858 parietalgm30=89634
temporalgm30=96928 wm30=614926 frontalwm30=230461 occipitalwm30=60727 parietalwm30=118151
temporalwm30=131192 abnormalwm30=11057 hippocampus30=8137 amygdala30=2201 entorarea30=3348
poscingyrus30=8161 precuneus30=20197 anaprioriscorebl=60 dnaprioriscorebl=77 gnaprioriscorebl=73
diabetes0=0 diabetes7=0 diabetes20=0 ICOGEXDAT=07/16/2015 ICOGIVID=156 ICOGEYEGL=2 ICOGBREYEGL=2
ICOGHA=1 ICOGBHA=. ICOGCOLOR1=2 ICOGCOLOR2=2 ICOGCOLOR3=2 ICOGCOLOR4=2 ICOGSPEECH=1 ICOGTREMOR=1
ICOGMISSEXT=1 ICOGOTHER=1 ICOGSTART=12:17 ICOGSTARTAMPM=2 ICOGSTOP=12:53 ICOGSTOPAMPM=2 I87SCORE1=3
I87SCORE2=6 I87SCORE3=6 I87SCORE4=8 I87SCORE5=7 I87INTSCORE=3 I87SCORE6=7 I87COMPTM=12:27
I87SDELAMPM=2 I87LDELTIM=12:36 I87LLDELAMPM=2 I87TOTDEL=9 I87SCORE7=6 I88TOTSC=34 I89NERR1=0
I89NCORR1=40 I89TOTSEC1=22 I89NERR2=0 I89NCORR2=40 I89TOTSEC2=24 I89NERR3=1 I89NCORR3=39
I89TOTSEC3=68 I94VSEPT=4 I94NAMPT=3 I94DIGPT=1 I94LETPT=0 I94SER7PT=3 I94LANGPT=2 I94LAFLPT=1
I94ABSTPT=1 I94DELRECPT=0 I94ORIENTPT=5 I94MOCATOT=20 I95REALMTOT=7 I94FWORDVAL=11 I96ATOT=9
I96AWORDVAL=6 I96STOT=15 I96SWORDVAL=15 I97ANIMVAL=17 I87TRIAL1=2 I87TRIAL2=2 I87TRIAL3=2
I87TRIAL4=2 I87TRIAL5=2 I87INTTRIAL=2 I87TRIAL6=2 I88TEST=2 I89TEST1=2 I89TEST2=2 I89TEST3=2
I87DEL=2 IMOCATEST=2 IREALMTEST=2 ILETATEST=2 ILETSTEST=2 ICATTEST=2 ICOGPHYS=. ICOGVIS=.
ICOGHEAR=. ICOGCNREAD=. ICOGINST=. ICOGNCOP=. ICOGTESTERROR=. ICOGOTHERN=. icogstroop=45
icogravlt=6 icogcatflu=17 icogletflu=32 icogdsst=34 icogmoca=20 icogrealm=7 A06FRU_CITFRUIT=0.85
A06FRU_FRUEXCIT=0.91 A06FRU_AVOCA=0 A06VEG_DARKGREEN=0 A06VEG_DEEPYELLOW=0.03 A06VEG_TOMATO=0.31
A06VEG_WHITEPOTATO=0.21 A06VEG_OTHSTARCH=0.27 A06VEG_LEGU=2.37 A06VEG_OTHER=1.38 A06GRW_WL=0
A06GRW_BDWL=0.06 A06GRW_OTHBDWL=0 A06GRW_CRKWL=0 A06GRW_PTWL=0 A06GRW_RTENSWL=0 A06GRW_RTESWL=0
A06GRW_CAKWL=0 A06GRW_SNKWL=0 A06GRW_CHIPWL=0 A06MRF_BEEF=1.38 A06MRL_LNBEEF=1.78 A06MRF_VEAL=0
A06MRL_LVEAL=0 A06MRF_LAMB=0 A06MRL_LNLAMB=0 A06MRF_FHPORK=0.8 A06MRL_LNFHPORK=0 A06MCF_CURPORK=0.2
A06MCL_LNCURPORK=0 A06MPF_POULTRY=0 A06MPF_LNPOULTRY=0.58 A06MFF_FISH=0 A06MFL_LNFISH=1.18
A06MSL_SHELLFISH=0 A06MCF_COLDCUT=0.32 A06MCL_LNCOLDCUT=0 A06MOF_ORGAN=0 A06DMF_WHMILK=2
A06DMF_RTDWHMILK=0 A06DCF_FULLFATCHEESE=0.09 A06DYF_YOGURTSTWHFAT=0 A06DYF_YOGURTARTSTWHF=0
A06FCF_CREAM=0 A06FAF_BUTTERRG=0.21 A06BVE_BEER=0.28 A06BVE_CORDIAL=0 A06BVE_DISTLIQUOR=0
A06BVE_WINE=0 fruit0=1.76 veggie0=1.99 potato0=0.21 legume0=2.37 grains0=0.06 fish0=1.18
rmeat0=4.48 poultry0=0.58 dairy0=2.3 alcohol0=0.28 D06FRU_CITFRUIT=0.07 D06FRU_FRUEXCIT=0.19
D06FRU_AVOCA=0 D06VEG_DARKGREEN=0.62 D06VEG_DEEPYELLOW=0 D06VEG_TOMATO=0.18 D06VEG_WHITEPOTATO=0.95
D06VEG_OTHSTARCH=0.3 D06VEG_LEGU=0.21 D06VEG_OTHER=0.43 D06GRW_WL=0 D06GRW_BDWL=0 D06GRW_OTHBDWL=0
D06GRW_CRKWL=0 D06GRW_PTWL=0 D06GRW_RTENSWL=0 D06GRW_RTESWL=0 D06GRW_CAKWL=0 D06GRW_SNKWL=0
D06GRW_CHIPWL=0 D06MRF_BEEF=0.37 D06MRL_LNBEEF=1.37 D06MRF_VEAL=0 D06MRL_LVEAL=0 D06MRF_LAMB=0
D06MRL_LNLAMB=0 D06MRF_FHPORK=0.43 D06MRL_LNFHPORK=0 D06MCF_CURPORK=0.19 D06MCL_LNCURPORK=1.33
D06MPF_POULTRY=0 D06MPF_LNPOULTRY=0.71 D06MFF_FISH=0 D06MFL_LNFISH=1.06 D06MSL_SHELLFISH=0.09
D06MCF_COLDCUT=1.22 D06MCL_LNCOLDCUT=0 D06MOF_ORGAN=0 D06DMF_WHMILK=0 D06DMF_RTDWHMILK=0
D06DCF_FULLFATCHEESE=0.06 D06DYF_YOGURTSTWHFAT=0 D06DYF_YOGURTARTSTWHF=0 D06FCF_CREAM=0
D06FAF_BUTTERRG=1.79 D06BVE_BEER=1.35 D06BVE_CORDIAL=0 D06BVE_DISTLIQUOR=0 D06BVE_WINE=0
fruit7=0.26 veggie7=1.53 potato7=0.95 legume7=0.21 grains7=0 fish7=1.15 rmeat7=4.91 poultry7=0.71
dairy7=1.85 alcohol7=1.35 G06FRU_CITFRUIT=0 G06FRU_FRUEXCIT=4.27 G06FRU_AVOCA=0
G06VEG_DARKGREEN=0.33 G06VEG_DEEPYELLOW=0.01 G06VEG_TOMATO=0.19 G06VEG_WHITEPOTATO=0.1
G06VEG_OTHSTARCH=0.27 G06VEG_LEGU=0.05 G06VEG_OTHER=0.93 G06GRW_WL=0 G06GRW_BDWL=0 G06GRW_OTHBDWL=0
G06GRW_CRKWL=0 G06GRW_PTWL=0 G06GRW_RTENSWL=0 G06GRW_RTESWL=0 G06GRW_CAKWL=0 G06GRW_SNKWL=0
G06GRW_CHIPWL=0 G06MRF_BEEF=1.1 G06MRL_LNBEEF=0.2 G06MRF_VEAL=0 G06MRL_LVEAL=0 G06MRF_LAMB=0
G06MRL_LNLAMB=0 G06MRF_FHPORK=0.37 G06MRL_LNFHPORK=0 G06MCF_CURPORK=0.11 G06MCL_LNCURPORK=0
G06MPF_POULTRY=0.52 G06MPF_LNPOULTRY=0.96 G06MFF_FISH=0 G06MFL_LNFISH=0.49 G06MSL_SHELLFISH=0
G06MCF_COLDCUT=0.39 G06MCL_LNCOLDCUT=0.2 G06MOF_ORGAN=0 G06DMF_WHMILK=0 G06DMF_RTDWHMILK=0
G06DCF_FULLFATCHEESE=0.06 G06DYF_YOGURTSTWHFAT=0 G06DYF_YOGURTARTSTWHF=0 G06FCF_CREAM=0
G06FAF_BUTTERRG=0.16 G06BVE_BEER=1.02 G06BVE_CORDIAL=0 G06BVE_DISTLIQUOR=1 G06BVE_WINE=0
fruit20=4.27 veggie20=1.73 potato20=0.1 legume20=0.05 grains20=0 fish20=0.49 rmeat20=2.37
poultry20=1.48 dairy20=0.22 alcohol20=2.02 rveggie0=3 rveggie7=2 rveggie20=2 rfruit0=4 rfruit7=1
rfruit20=5 rpotato0=3 rpotato7=5 rpotato20=2 rgrains0=1 rgrains7=0 rgrains20=0 rfish0=4 rfish7=4
rfish20=3 rlegume0=5 rlegume7=4 rlegume20=2 rpoultry0=3 rpoultry7=2 rpoultry20=4 rdairy0=3
rdairy7=3 rdairy20=1 ralcohol0=3 ralcohol7=5 ralcohol20=5 r_rmeat0=4 r_rmeat7=5 r_rmeat20=3
rmonosat0=5 rmonosat7=3 rmonosat20=4 i=. new_rpoultry0=2 new_rpoultry7=3 new_rpoultry20=1
new_rdairy0=2 new_rdairy7=2 new_rdairy20=4 newr_rmeat0=1 newr_rmeat7=0 newr_rmeat20=2
new_rmonosat0=4 new_rmonosat7=2 new_rmonosat20=3 meddiet0=29 meddiet7=23 meddiet20=24
meddietavg=25.333333333 avgdbp=83.666666667 avgsbp=134 avgincome=8 avgtrig=111.33333333 avghdl=54
avgldl=364 avgglucose=93.836481535 avgpact=378.33333333 edu_max=2 smoke_max=2 diabetes_max=0
weightkg0=82.628 weightkg7=98.972 weightkg20=105.782 heightm0=1.87 heightm7=1.885 heightm20=1.895
_I_=. htn0=0 htn7=0 htn20=1 bmi0=. bmi7=. bmi20=. l=. _ERROR_=1 _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.DIET6.
WARNING: The data set WORK.DIET6 may be incomplete. When this step was stopped there were 0
observations and 439 variables.
WARNING: Data set WORK.DIET6 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.12 seconds

Astounding
PROC Star

Your array definitions are improper.  They use a form of the ARRAY statement that was discontinued over 30 years ago.  (It is still supported, but is not compatible with the way you reference array elements later in the DATA step.)  For example, you use:

array dbp  dbp0 dbp7 dbp20;

Instead, you should add the number of elements in the array:

array dbp  (3) dbp0 dbp7 dbp20;

Alternatively, if you don't want to count the elements but intend to use the DIM function as you have, you could use:

array dbp  (*) dbp0 dbp7 dbp20;

It is difficult to envision why the old style would generate the errors you encountered.  Still, fix the known issue first, and see what errors remain.

 

As a side note, these variables get assigned values of "0" or "1":

array  htn (3) htn0 htn7 htn20;

If those variables are existing character variables, that is fine.  But if they don't already exist before the DATA step begins, they will be defined as numeric.  If they should be numeric, just remove the quotes (0 or 1, not "0" or "1").  If they are new, and should be created as character variables with a length of 1, indicate that in the ARRAY statement:

array  htn (3) $ 1 htn0 htn7 htn20;
WarrenKuhfeld
Rhodochrosite | Level 12
do i=l to dim(weightkg);

Change i=l to i=1. One not letter l.

Tom
Super User Tom
Super User

That is not an issue in a DATA step.  The dimension of the array does not need to be specified, not even by adding the unnecessary [*] fluff.  There are some PROCs that support data step like code that do require it.

 

There must be something else going on.  Like the DO statement getting eaten by an unclosed comment. That would lead to I not be initialized.

 

Or perhaps confusion between i and L in the code.

ballardw
Super User

Read your code and read the log.

If you look not so closely at the highlighted code below you will see that one of the characters is numeral for one, the other is a letter , lower case L. So unless you have a numeric variable named L that has a value inside the valid range for the array using that part of the loop, it starts i with an invalid value. If you do not have a variable L the first value of I is missing. 1 l  0 O  , one L, zero capital O are two ancient and common coding problems.

data diet6;
set diet6;
array dbp  dbp0 dbp7 dbp20;
array sbp  sbp0 sbp7 sbp20;
array  htn htn0 htn7 htn20;
do i=1 to dim(dbp);
if dbp(i)ge 90 and sbp(i) ge 140 then htn(i)= "1";
else htn(i)= "0";
end;
array weightkg weightkg0 weightkg7 weightkg20;
array heightm  heightm0 heightm7  heightm20;
array bmi bmi0 bmi7 bmi20;
do i=l to dim(weightkg);
bmi(i)= (weightkg(i))/(heightm(i))**2;
end;

 

Tom
Super User Tom
Super User

This a good example of where the DO OVER syntax that SAS has removed from the documentation would actually work a LOT better.   The index into those arrays do not have any meaning.  They do not match the suffixes on the variable names.  There is no reason that you need to process the 0 or 7 variables before the 20 variables.  And if you don't have to write out the do loop boundaries then you are not at risk of making a typo when doing so.

data diet6_new;
  set diet6;
  array dbp  dbp0 dbp7 dbp20;
  array sbp  sbp0 sbp7 sbp20; 
  array htn $1 htn0 htn7 htn20;
  do over dbp;
    if dbp ge 90 and sbp  ge 140 then htn= "1";
    else htn= "0";
  end;
...

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1126 views
  • 6 likes
  • 6 in conversation